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

Enhancements to Handle Selected Text and Error Prevention #8

Merged
merged 3 commits into from
Aug 9, 2024

Conversation

Rod-Gomes
Copy link
Contributor

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.

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.
Ensuring Accurate Text Selection
@ecornell ecornell merged commit d8f170a 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