Skip to content

Fix intermittent mouse selection failure in source editor - #16815

Merged
kevinushey merged 1 commit into
mainfrom
bugfix/ace-mouse-handler-error-recovery
Jan 13, 2026
Merged

kevinushey merged 1 commit into
mainfrom
bugfix/ace-mouse-handler-error-recovery

Conversation

@kevinushey

@kevinushey kevinushey commented Jan 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Adds automatic detection and recovery for corrupt Ace mouse handler state
  • When an uncaught JavaScript exception occurs during mouse event handling, the MouseHandler can be left in an inconsistent state where mouse selection stops working for that editor tab
  • Recovery is triggered when tabs are activated, so switching away and back to an affected tab will restore functionality

Addresses #13436

Details

The root cause analysis suggests that Ace's MouseHandler can get stuck in a corrupt state when:

  • An exception occurs during onCaptureEnd before cleanup code runs
  • The inVirtualSelectionMode flag gets stuck true in multi-select scenarios
  • The state property remains at a non-empty value like "select" or "drag"

This PR adds two methods to AceEditorNative:

  • isMouseHandlerStateCorrupt() - detects suspicious state combinations (e.g., non-empty state when mouse is not pressed)
  • resetMouseHandlerState() - resets all relevant state variables to their default values

The check runs in AceEditorWidget.onActivate(), so whenever a user switches to a tab with corrupt state, it will be automatically recovered.

Test plan

  • Verify normal mouse selection still works correctly
  • Verify multi-cursor selection (Alt+click) still works
  • Verify drag-and-drop text still works (if enabled)
  • If the bug can be reproduced, verify that switching tabs recovers the editor

🤖 Generated with Claude Code

Add automatic detection and recovery for corrupt Ace mouse handler
state. When an uncaught JavaScript exception occurs during mouse event
handling, the MouseHandler can be left in an inconsistent state where
mouse selection stops working for that editor tab.

This fix adds:
- isMouseHandlerStateCorrupt(): detects suspicious state combinations
- resetMouseHandlerState(): resets all mouse handler state variables
- Automatic recovery check when editor tabs are activated

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@posit-snyk-bot

posit-snyk-bot commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gtritchie gtritchie added this to the Globemaster Allium milestone Jan 12, 2026
@gtritchie

Copy link
Copy Markdown
Member

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kevinushey
kevinushey merged commit 47a882c into main Jan 13, 2026
@kevinushey
kevinushey deleted the bugfix/ace-mouse-handler-error-recovery branch January 13, 2026 00:47
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.

3 participants