Skip to content

route rmd chunk execution through the focused editor view - #18521

Merged
kevinushey merged 4 commits into
mainfrom
bugfix/split-editor-rmd-chunks
Aug 13, 2026
Merged

kevinushey merged 4 commits into
mainfrom
bugfix/split-editor-rmd-chunks

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

When a document's editor is split (#2129, added in #18460), several R Markdown chunk-execution paths ignored which view held the cursor:

  • Run Current Chunk, Run Next Chunk, and Run Previous/Subsequent Chunks resolved the target chunk from the primary view's cursor, so invoking them with the split view focused ran the wrong chunk.
  • Run Line inside a chunk bypassed the notebook queue when initiated from the split view and executed at the console instead: the inline-chunk-output flag lives on each editor view, and it was never applied to the split view.

This PR resolves chunk positions from the focused view (positions are document-wide, so the primary view's scope tree can still service them), lands cursor/scroll feedback in the view that initiated the execution, and keeps the split view's inline-output flag in sync -- at split creation, and whenever the notebook changes the output mode.

It also assigns a stable class (rstudio_editor_split_view, via ClassIds) to the split editor view so automation and styling can tell the two views of a document apart; the new Playwright suite uses it.

Chunk output widgets and chunk toolbars still render only in the primary view's session; fanning those out to every view is tracked as follow-up work.

Includes a Playwright regression suite (split_editor_rmd.test.ts) covering both execution paths.

Addresses #2129.

Assign a stable automation/styling class (rstudio_editor_split_view) to
the secondary editor view, so tests and tooling can tell the two views
of a document apart without probing rendered text.
Run Current Chunk, Run Next Chunk, and Run Previous/Subsequent Chunks
resolved the target chunk against the primary view's cursor, so with a
split editor focused they ran the wrong chunk. Resolve chunk positions
from the active view instead (positions are document-wide, so the
primary view's scope tree can still service them), and land cursor and
scroll feedback in the view that initiated the execution.

Run Line inside a chunk also bypassed the notebook queue when initiated
from the split view: the inline-chunk-output flag lives on each editor
view and was never applied to the split, so execution fell through to
the console. Sync the flag to the split view at creation and whenever
the notebook changes the output mode.
@kevinushey kevinushey added this to the 2026.09 (Autumn Hawkbit) milestone Aug 11, 2026
@github-actions

github-actions Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
2120 0 394 1
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 8 0
✅ desktop-linux 529 0 90 0
✅ desktop-macos 525 0 95 0
✅ desktop-windows 525 0 99 1
✅ server-linux 517 0 94 0
✅ setup 22 0 8 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit 24b78d1ffa186ca6ee673a2047ca1943c0f62752 - Run #564

@gtritchie

Copy link
Copy Markdown
Member

Code review findings

Actionable items from an automated review of this PR's diff.

Important

  1. src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java:6956 — Run Previous/Subsequent Chunks still resolves from the primary view. executeScopedChunks gets pos from withVisualModeSelection, which in source mode passes docDisplay_.getCursorPosition(), so executeChunks(pos, dir) never sees null and the new position == null -> activeDisplay().getSelectionStart() fallback at line 6965 is unreachable (no caller passes null). With the split view focused in chunk 3 and the primary cursor in chunk 1, Run All Chunks Above runs the chunks above chunk 1. Fix: resolve the position from activeDisplay() in executeScopedChunks (or pass null through to executeChunks).

  2. e2e/rstudio/tests/panes/editor/split_editor_rmd.test.ts:98 — openAndSplit calls consoleActions.evalRLogical after focusing the split view; that helper focuses the console input, so the later page.keyboard.press('Control+Enter') is delivered to the console, not the split editor. The Run Line test can then only pass via the splitEditorFocusedLast_ flag, so it does not verify keyboard routing into the focused view. Fix: clear the globals before focusing the views, as split_editor.test.ts does.

  3. e2e/rstudio/tests/panes/editor/split_editor_rmd.test.ts:128 — the lineWidgetCount() baseline is captured immediately after open/split, but chunk toolbars are line widgets created asynchronously when the notebook's scope tree becomes ready. If the toolbars land after the baseline, the primary count goes 0 -> 3 and toBe(widgetsBefore + 1) only passes if a poll tick catches the transient value: intermittent failure. Fix: wait for the toolbars before capturing the baseline, or assert on the widget at a specific row.

Suggestions

  1. src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTargetScopeHelper.java:161 — the no-arg getNextSweaveChunk() has no callers left in src/gwt after the call site moved to the Position overload. It reads the primary view's selection, so a future caller picking it up silently reintroduces this bug. Fix: remove it.

  2. src/gwt/src/org/rstudio/studio/client/workbench/views/source/editors/text/TextEditingTarget.java:7236 — executeSweaveChunk moves cursor/scroll feedback to the initiating view but still records the executed range on codeExecution_ (the primary view's executor). Running a chunk from the split view highlights the last-executed range in the primary view, and if the previous Run Line came from the split view, lastCodeExecution_ still points at splitCodeExecution_ with its older range, so Re-Run Previous Code re-runs that instead of the chunk just executed.

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

Feedback posted

- withVisualModeSelection now reads the source-mode cursor from the
  active editor view, so Run Previous/Subsequent Chunks resolve from
  the split view when it holds the cursor
- executeSweaveChunk records the executed range on the initiating
  view's executor, so Re-Run Previous re-runs the chunk it just ran
  instead of that executor's older range
- drop the unused no-arg scope-helper variants, which silently read
  the primary view's selection
- clear console state before focusing the views, so the Run Line
  keypress is actually delivered to the focused split editor
- wait for the async chunk toolbars before capturing the line-widget
  baselines
- use a unique file per test: reopening a path whose content matches
  a previously executed notebook restores its cached output widgets
- add a regression test for Run All Chunks Above from the split view
- fix tsc errors (gotoLine arity, element handle typing)
@kevinushey

Copy link
Copy Markdown
Collaborator Author

Thanks -- all five were on target, applied in 5bed5a7 and 24b78d1.

  1. Fixed the real path: withVisualModeSelection(CommandWithArg<Position>) now reads the source-mode cursor from activeDisplay(), so executeScopedChunks follows the focused view (the null fallback in executeChunks remains as null-safety). Added an e2e test covering Run All Chunks Above from the split view.
  2. Fixed -- the console cleanup now runs before the views are focused, as in split_editor.test.ts, so the keypress genuinely lands in the split editor.
  3. Fixed -- openAndSplit waits for the two chunk toolbars before the tests capture baselines. Local runs surfaced a second source of drift while fixing this: reopening the same path restores cached chunk output widgets from the notebook cache, so each test now uses a unique file name.
  4. Removed, along with the equally dead getCurrentSweaveChunk()/getPreviousSweaveChunks() no-arg variants -- same primary-view-selection hazard.
  5. Half-right: setLastExecuted creates an invisible AnchoredSelection, so nothing is highlighted. But the stale lastCodeExecution_ was real -- executeSweaveChunk now records the executed range via codeExecution(), so Re-Run Previous re-runs the chunk that just ran regardless of which view initiated it.

@kevinushey
kevinushey merged commit 5c0ff6e into main Aug 13, 2026
27 checks passed
@kevinushey
kevinushey deleted the bugfix/split-editor-rmd-chunks branch August 13, 2026 17:37
@gtritchie gtritchie mentioned this pull request Aug 31, 2026
3 of 4 tasks
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