Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fixes and Error Handling Improvements #10

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

Rod-Gomes
Copy link
Contributor

Changes:

  1. Bug Fix in SelectText() Function

    • Ensured clipboard is cleared before copying text to fix selection issues.
  2. Input Length Validation in CallAPI() Function

    • Added check to prevent API requests if input length is less than 1 character.
  3. Error Handling and Cursor Restoration in CallAPI() Function

    • Wrapped API request in a try-catch block.
    • Restored cursor and reset _running state before displaying error messages.

Changes:

1. Conditionally Show Wait Tooltip: 
   - Moved the `ShowWaitTooltip()` call to occur only after successfully ensuring that text is selected.

2. Set System Cursor:
   - The line to set the system cursor to the wait state was moved to occur after checking if the text was successfully retrieved from the clipboard.

3. Error Handling in `PromptHandler`:
   - Wrapped the `GetTextFromClip()` call in a try-catch block within the `PromptHandler` function to handle cases where no text is selected.
   - If an error is caught (indicating no text is selected), `_running` is set to `false`, the cursor is restored, and the function returns early, preventing further processing or API calls.

4. Text Selection Logic:
   - Enhanced the text selection logic to check if text is already selected. If text is already selected, it doesn't re-select all text.
   - If no text is selected, it defaults to selecting all text.

These changes ensure that the script only attempts to generate a response if text is selected, providing appropriate feedback to the user when no text is selected without proceeding to make unnecessary API calls.
The `SelectText()` function has been updated to ensure corrections are made only to selected text. If no text is selected, it will automatically select text based on the active application:
- For Word/Outlook: selects the entire paragraph.
- For Notepad++/VS Code: selects the entire line.
- For other applications: selects all text.

This ensures that the script respects existing text selections and only performs automatic selection when no text is selected.
Changes:

1. Bug Fix in `SelectText()` Function
   - Ensured clipboard is cleared before copying text to fix selection issues.

2. Input Length Validation in `CallAPI()` Function
   - Added check to prevent API requests if input length is less than 1 character.

3. Error Handling and Cursor Restoration in `CallAPI()` Function
   - Wrapped API request in a try-catch block.
   - Restored cursor and reset `_running` state before displaying error messages.
@ecornell ecornell merged commit eea60f6 into ecornell:main Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants