Advance cursor to next code chunk after executing last line - #1127
Open
jeroenjanssens wants to merge 1 commit into
Open
jeroenjanssens wants to merge 1 commit into
jeroenjanssens wants to merge 1 commit into
Conversation
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. |
When running code line-by-line with Cmd+Enter, executing the last line of a code chunk now moves the cursor to the first line of the next chunk instead of falling into prose. Related: quarto-dev#704
jeroenjanssens
force-pushed
the
advance-cursor-next-chunk
branch
from
September 15, 2026 18:30
8fad34a to
f76fcb3
Compare
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.
Summary
When running code line-by-line with Cmd+Enter, executing the last line of a code chunk causes the cursor to "fall out" of the chunk into prose. This is disruptive because the next chunk could be dozens of lines away and the user has to navigate back manually. Worse, if the user keeps pressing Cmd+Enter, the interpreter will try to execute the closing fence or prose text, leading to errors.
With this change, executing the last line of a code chunk moves the cursor to the first line of the next code chunk (if one exists). If there's no next chunk, the cursor lands on the closing fence as before.
This covers three code paths in
RunCurrentCommand:executeAtPositionpath)The "run entire cell" paths (plain VS Code with Python/R, non-knitr visual editor) are unaffected since they don't do line-by-line execution.
Related
#704 describes the same trigger (Cmd+Enter on the last line exits the chunk), though the author there preferred the cursor to stay put rather than advance. Both behaviors could coexist: this PR handles advancing to the next chunk, while Positron's Alt+Enter (posit-dev/positron#2778) already supports executing without moving the cursor.