Skip to content

Preserve code chunk selection when restoring visual editor focus - #1153

Open
kv9898 wants to merge 1 commit into
quarto-dev:mainfrom
kv9898:fix/visual-editor-focus
Open

kv9898 wants to merge 1 commit into
quarto-dev:mainfrom
kv9898:fix/visual-editor-focus

Conversation

@kv9898

@kv9898 kv9898 commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Switching back to Positron from another application can move the visual editor's caret to the start of a code chunk. During focus restoration, focusing the outer ProseMirror editor can clear the browser selection before CodeMirror regains focus; CodeMirror then reads that DOM selection and resets its cursor.

Allow an extension to handle focus before the outer editor. When a text selection is wholly inside a CodeMirror chunk, restore that selection and focus CodeMirror directly. Other selections retain the existing focus path. The restoration delay and the separate editor-tab focus behavior are unchanged.

References #340 and posit-dev/positron#4248.

Validation:

  • Manually reproduced the original failure in Positron and confirmed that the final implementation preserves the caret, selected code, and ordinary prose behavior across application switching.
  • VS Code extension, visual editor, and browser fixture TypeScript checks pass.
  • Browser fixture passes seven DOM restoration cases (start/middle/end, forward/backward selections, nested and empty chunks), prose focus, and three fallback-routing checks.
  • Negative control: substituting the original outer-editor focus path fails the no-outer-focus assertion. A separate browser check confirms typing at the restored caret.

Run the browser fixture from the repository root:

node node_modules/vite/bin/vite.js packages/editor-codemirror/test

Open the printed local URL at /focus.html. No new dependencies are required. The fixture verifies restoration and routing; it does not reproduce the complete native application-switch failure on the original path. That failure and the final fix were verified manually in Positron.

@posit-snyk-bot

posit-snyk-bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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

Status Scan Engine 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.

@kv9898
kv9898 marked this pull request as ready for review September 26, 2026 10:23
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