don't treat programmatic selection changes as cursor movement in AceNodeView - #1100
Open
kevinushey wants to merge 1 commit into
Open
Conversation
AceNodeView.setSelection() sets this.updating, focuses the Ace editor and applies the selection range; that fires 'changeCursor', so cursorDirty was set even though the user never moved the cursor. The next Ace render then called scrollCursorIntoView() and scrolled the editing root to that node view. ProseMirror calls setSelection() from selectionToDOM() on every EditorView.focus(), so any focus restore scrolled the document to whichever embedded editor held the selection -- for a freshly opened document that is the YAML front matter block, at the very top. Addresses quarto-dev#1099.
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1099.
AceNodeView.setSelection()setsthis.updating, focuses the Ace editor and applies a selection range. That fireschangeCursor, and the handler setcursorDirtywithout consultingthis.updating— so the next Ace render calledscrollCursorIntoView()and scrolled the editing root to that node view, even though nothing moved the cursor. The value-change handlers just above (L508/L513) already guard onthis.updating; this one didn't.ProseMirror calls
setSelection()fromselectionToDOM()on everyEditorView.focus(), so any focus restore scrolled the document to whichever embedded editor held the selection. For a freshly opened document that selection is at position 0 — the YAML front matter block — so the document snapped to the very top. In RStudio this shows up as the visual editor jumping to the top of the document whenever you run a code chunk in a file you have just opened (rstudio/rstudio#18490); clicking once anywhere in the prose moves the selection out of anAceNodeViewand the symptom disappears until the file is reopened.Verification
Tested against an RStudio development build by serving a patched
panmirror.jsto the browser and leaving everything else identical, measuring.pm-scroll-containerscrollTop across a chunk run:Genuine cursor-driven scrollback is unchanged: scrolling a focused code chunk out of view and pressing an arrow key still brings the cursor back into view, identically before and after.
Notes
No
apps/vscode/CHANGELOG.mdentry —aceExtensionis only installed whenoptions.codeEditor === 'ace'(editor-extensions.ts:222), which is RStudio's configuration; the VS Code and Positron visual editors use the CodeMirror code view and are unaffected. Happy to add an entry if you'd rather have one.