Skip to content

add null check in multiselect change handler - #14804

Merged
kevinushey merged 1 commit into
mainfrom
bugfix/ace-multiselect-null-check
Jun 7, 2024
Merged

kevinushey merged 1 commit into
mainfrom
bugfix/ace-multiselect-null-check

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

A potential fix for #13605.

Includes a debugger call just so we can request users attempt to capture this and provide more details if / when it occurs. (The debugger call should be a no-op if no DevTools window is open.)

@kevinushey
kevinushey requested a review from gtritchie June 7, 2024 16:37

@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.

What changed in Ace itself (diff too large to be seen, and wouldn't be useful anyway, I imagine)?

@kevinushey

Copy link
Copy Markdown
Collaborator Author

@kevinushey
kevinushey merged commit 7bb5dbb into main Jun 7, 2024
@kevinushey
kevinushey deleted the bugfix/ace-multiselect-null-check branch June 7, 2024 20:57
@gtritchie

Copy link
Copy Markdown
Member

Oh duh, I didn't connect the dots between uncompressed and compressed ace.js.

gtritchie added a commit that referenced this pull request Aug 4, 2026
* recover from corrupt ace multi-select editor state

An exception escaping into Ace's multi-select machinery could leave a
source editor permanently broken until the IDE was reloaded: mouse text
selection dead, typed input silently discarded, multi-select mode
impossible to exit, and editor commands landing in a previously focused
tab. Ace's forEachSelection() and $moveLines() mutate selection state
(temporary Selection object, silenced event registry,
inVirtualSelectionMode, detached range list) and restore it with no
exception protection, so a single mid-operation throw stranded that
state permanently.

This change fixes and hardens things on the RStudio side, leaving the
bundled Ace behavior untouched so the defects can be reported upstream
against stock Ace:

- acesupport mixin (mixins/multi_select_guard) wraps forEachSelection
  and $moveLines with snapshot/restore semantics, so an aborting
  exception no longer strands the temporary selection, the silenced
  event registry, inVirtualSelectionMode, or a detached range list
- AceEditorNative gains isMultiSelectStateCorrupt() and
  resetMultiSelectState(), extending the #13436 mouse-handler recovery
  to detect and repair leftover multi-select corruption; the check now
  also runs (deferred) when an editor regains focus
- AceEditor.focus() updates the last-focused-editor tracking eagerly,
  so editor commands (e.g. insert pipe operator) cannot target a
  previously focused tab when the DOM focus event does not re-fire
- applyChanges() and doSetCode() exit multi-select mode before driving
  command streams / replacing the document from async contexts
- AceEditorNative.setHandler() callback is now $entry-wrapped, closing
  the one Ace-to-GWT callback that let GWT exceptions propagate raw
  into Ace's dispatch
- removed a stray debugger; statement (shipped in both ace bundles
  since the #14804 null guard) that froze the IDE whenever devtools
  were open and the guard was reached

The new Playwright spec injects a throwing document listener during a
multi-cursor edit and asserts the editor survives; without the mixin it
reproduces the corruption (stuck inVirtualSelectionMode, stranded
temporary selection) deterministically.

Addresses #13605.

* document intentional inVirtualSelectionMode omission; log failed resets

* address code review feedback for multi-select recovery

- run only the multi-select corruption check from the focus path: the
  mouse-handler check misfires during an Alt+drag block selection, whose
  mousedown stops the event before the default capture handler runs
  (isMousePressed stays false while inVirtualSelectionMode is set)
- have the corruption detector return a reason string so recovery logs
  say which corruption branch fired
- resetMultiSelectState: restore session.$undoSelect (addRange clears
  it, and the bypassed $onRemoveRange is what normally restores it);
  log failures in the individual recovery steps; repair the selection
  marker count after a failed marker removal; and on a $onSingleSelect
  failure remove the 'exec' rerouting handler explicitly and keep the
  editor flagged as corrupt so the reset is retried
- doSetCode/applyChanges: reset stranded corrupt state instead of
  calling the silently no-op exitMultiSelectMode; log when extra
  cursors are dropped
- focus(): claim s_lastFocusedEditor only when focus actually landed,
  so focusing a hidden or detached editor can't steal command routing
- multi_select_guard: describe each wrapped function's behavior
  separately, name the Ace internals the wrappers depend on, and log
  which stranded state a finally block repaired
- e2e: prove fault injection with a window sentinel instead of
  exception routing; assert exact cursor and insertion counts; add
  coverage for the $moveLines guard, a healthy multi-cursor selection
  surviving tab switches, a detached-range-list corruption shape, and
  focus-path repair without a tab switch

* add basic multi-select e2e tests

Pin the everyday multi-select behaviors that the multi_select_guard
wrappers must leave intact -- typing at keyboard-added cursors,
single-step undo of a multi-cursor edit, splitIntoLines, and moving
lines with multiple cursors -- driven through the real keyboard
shortcuts. Addresses #13605.

---------

Co-authored-by: Gary Ritchie <[email protected]>
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