Skip to content

Advance cursor to next code chunk after executing last line - #1127

Open
jeroenjanssens wants to merge 1 commit into
quarto-dev:mainfrom
jeroenjanssens:advance-cursor-next-chunk
Open

jeroenjanssens wants to merge 1 commit into
quarto-dev:mainfrom
jeroenjanssens:advance-cursor-next-chunk

Conversation

@jeroenjanssens

Copy link
Copy Markdown
Contributor

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:

  • Source editor (Positron, VS Code with R extension, fallback executors)
  • Visual editor, Positron (executeAtPosition path)
  • Visual editor, non-Positron knitr (line-by-line path)

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.

@posit-snyk-bot

posit-snyk-bot commented Sep 15, 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.

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
jeroenjanssens force-pushed the advance-cursor-next-chunk branch from 8fad34a to f76fcb3 Compare September 15, 2026 18:30
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