You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(notebook): scroll the notebook while a cell selection drag leaves the pane - #51764
In a Jupyter notebook, if you click inside a cell and drag down (or up) to select text, the notebook now scrolls with you once your pointer goes past the bottom (or top) of the pane, and the selection keeps growing. Before, the selection stopped at the last line you could see.
What Changed
Before: Dragging a selection in a tall code or Markdown cell past the pane edge did nothing. The notebook did not scroll, and the selection stayed on the last visible line.
After: While a left-button selection drag is held past the pane's bottom edge, or over the sticky header at the top, the notebook scrolls every frame and the selection follows the newly visible lines. Releasing ends it. Scrolling never starts while the pointer is still inside the pane, so double-clicks, clicks on the edge lines and in-pane drags behave as before.
Mechanism: Notebook cells are sized to fit their content, so Monaco never scrolls internally. Its own drag edge-scroll only starts once the pointer leaves the editor node, which is taller than the pane and clipped. The notebook's overflow-auto root had no drag autoscroll.
New ipynb-selection-scroll.ts, installed once per active cell editor. A content mousedown adds window pointer listeners (capture) and runs a rAF loop that scrolls the notebook root using the shared getDragAutoScrollStepPx.
Each frame, the loop replays the held pointer at a y clamped into the pane, so Monaco's own drag extends the selection. Word and line drag modes keep working.
Cells over the 200-line cap fall back to Monaco's inner scroll once the notebook reaches the cell edge.
Dragging selected text to move it (drag-and-drop) never scrolls.
Everything is torn down on pointerup, pointercancel, a buttons change, window blur, Escape (Monaco refuses the replay), the next mousedown, or editor dispose.
IpynbViewer adds data-ipynb-viewport and data-ipynb-header hooks so the helper can find the scroll root and the sticky header.
Why
Native selection autoscroll can't help here because Monaco preventDefaults the mousedown. Making cells scroll internally would break the content-sized notebook layout. Replaying the held pointer through Monaco's own drag handler keeps its selection semantics (word/line modes, Shift, Escape, text-move rules). We only add the outer scroll, the same way Monaco's TopBottomDragScrolling replays its last mouse event every frame.
Recorded in a hidden Electron e2e build on a remote macOS machine. A 100-line code cell in a 940 px pane: press on line 4, drag past the pane bottom and hold.
Before (main): the notebook does not scroll and the selection stops at the edge line.
51764-before.webm
After: the notebook scrolls and the selection follows to the cell end.
51764-after.webm
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
ipynb-selection-scroll.test.ts is a pure unit test of the pane-edge gate and clamp helper. It checks:
no scroll anywhere inside the pane, including the edge pixels
a positive step with y clamped past the bottom
a negative step with y clamped over the header
It fails against the earlier in-band gate. The drag and scroll wiring needs real Monaco and real pointer events, so it was proven with hidden-Electron e2e scratch specs on macOS instead of a committed UI test.
Reproduced on main: scrollTop stays 0 -> 0 and the cursor stays stuck on the edge line (42) for the whole hold.
With the fix:
code cell down: scroll 15 -> 844, cursor 43 -> 84 (equal to the edge line)
code cell up: scroll 829 -> 98.5, cursor -> 1
Markdown cell: scroll 2147 -> 2976, cursor -> 89
edge-line drag straight out of the pane: down 0 -> 1166.5, up 900 -> 98.5
word drag from the edge line: scrolls to the cell end
capped 300-line cell: cursor 4 -> 300
pointer past the pane is clamped to the visible edge line
Escape mid-drag stops scrolling immediately
wheel scrolling is unaffected, and an idle hover at the edge with no button held does not scroll
dragging a selected word to move it does not scroll
Static gates pass on the touched files: oxlint, oxfmt --check, anti-slop oxlint, code-quality native and type-aware oxlint, ast-grep, and check-changed-code-quality.mjs.
Platforms: macOS runtime. The change is renderer-only. On Linux, pointer capture fails and Monaco listens on window, and the bubbling replay still reaches it (checked against Monaco 0.55.1 source). SSH and remote workspaces use the same renderer path.
Performance
This only runs while a left-button selection drag is held after a press on cell text. There are no listeners otherwise, and no polling, timers, I/O, IPC or subprocesses.
Measured with CDP renderer ScriptDuration over a 900 ms edge hold (about 55 frames at 60 Hz) on macOS:
main: 0.6-10 ms, because nothing scrolls (that is the bug)
this PR: 51-67 ms, about 1 ms per edge-scroll frame
Max frame gap is 18.4-18.7 ms in every arm, main included (vsync jitter). No frame stalls.
A still pointer that can't scroll schedules no frames. Inside the pane, a frame bails after two rect reads.
Fanout: one install per active Monaco cell. At N=200 cells, a drag frame does 0 work for the other 199 cells, same as main.
Risk
Level: Low
The riskiest part is the synthetic pointermove replay into Monaco's drag. If Monaco stops handling it (for example after a Monaco upgrade), the loop stops at the first refused replay, and the notebook falls back to today's behavior of not scrolling. The change is renderer-only, with no saved data or settings. A plain revert backs it out.
Review
Reviewed for correctness, security and performance.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Covers selection within a single cell (no cross-cell selection). No security, mobile or backwards-compatibility impact.
Original fix by @dzkchen in #51764. Their authorship is preserved on the commit.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
The notebook viewer now marks its viewport and sticky header. The cell editor installs a handler that tracks eligible selection drags, scrolls the notebook near its boundaries, and scrolls the editor when notebook scrolling cannot advance. The handler replays pointer moves to extend selection and stops on pointer termination, window blur, or editor disposal.
Severity of issue fixed: Medium
Merge Risk: Low · up to 7eceb
Notebook text selection now auto-scrolls when dragging past the pane edge. A few narrow edge cases remain, such as a Shift-initiated selection held still at the edge, a pointer within a pixel of a fractional pane boundary, and very short panes. These cause minor scroll glitches and do not block the feature. It is mergeable with these noted as follow-ups.
Pre-merge checks: 4
Check name
Status
Explanation
Linked Issues check
Objective [#51757]: during a left-button selection drag in a notebook code cell, the notebook should scroll when the pointer is held beyond the pane edge, and the selection should extend past the last…
Out of Scope Changes check
All changed files relate to the issue objective. IpynbCellEditor.tsx (+2 lines) wires the new handler into the editor. ipynb-selection-scroll.ts implements edge scrolling and pointer replay for select…
Title check
The title names the main change: notebook scrolls while a cell selection drag leaves the pane. It uses the conventional fix(notebook) prefix and is specific. It is 78 characters, slightly above a typi…
Description check
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #51757), Visual Proof with before/after videos, Testing, Performance, Risk with level Low a…
Full details: Linked Issues check
Explanation
Objective [#51757]: during a left-button selection drag in a notebook code cell, the notebook should scroll when the pointer is held beyond the pane edge, and the selection should extend past the last visible line. Evidence: ipynb-selection-scroll.ts installs a drag handler on the Monaco editor. It scrolls the [data-ipynb-viewport] element near the [data-ipynb-header] or the viewport bottom, using a signed step from getIpynbSelectionScroll, so upward drags are covered. It then replays the pointer into Monaco at a clamped position so Monaco extends the selection. For capped cells, it falls back to Monaco's inner scroll. IpynbCellEditor.tsx calls installIpynbSelectionScroll(editorInstance, container) during editor creation. IpynbViewer.tsx adds the data-ipynb-viewport and data-ipynb-header attributes. The Markdown-cell reproduction in the issue is now confirmed: IpynbCellEditor.tsx renders IpynbSourceEditor for any active cell, including active Markdown cells. Only inactive Markdown cells render the preview, so the handler covers editing Markdown cells. The current head also adds ipynb-selection-scroll.test.ts, which covers getIpynbSelectionScroll clamping and scroll direction. The issue does not require automated tests. Uncertainty: the incremental diff since the previous reviewed head could not be read, so the handler behavior is taken from the whole-PR summary and the previous assessment, not from a direct read of the changed lines. The PR reports manual macOS checks only; Windows, Linux, and remote workspaces are not runtime-verified, but the issue scope is desktop use.
Full details: Out of Scope Changes check
Explanation
All changed files relate to the issue objective. IpynbCellEditor.tsx (+2 lines) wires the new handler into the editor. ipynb-selection-scroll.ts implements edge scrolling and pointer replay for selection drags. IpynbViewer.tsx (+5/-1) adds the data attributes the handler queries. ipynb-selection-scroll.test.ts (+25 lines) tests the scroll-step helper that the handler uses, so it supports the same objective. The layout-change invalidation and drag-cancel handling described in the PR belong to the same drag-selection behavior. Uncertainty: the incremental diff could not be read, so the changes since the previous review are assessed from the whole-PR summary and current file contents only.
Full details: Title check
Explanation
The title names the main change: notebook scrolls while a cell selection drag leaves the pane. It uses the conventional fix(notebook) prefix and is specific. It is 78 characters, slightly above a typical short title, but this does not affect relevance.
Full details: Description check
Explanation
The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Fixes #51757), Visual Proof with before/after videos, Testing, Performance, Risk with level Low and revert instructions, AI Disclosure, Review, Agent skill boundary, Notes, and Checklist. The Performance section gives measured numbers and a one-line rationale. The Risk section names the riskiest part and the revert path. The AI Disclosure section is left blank, which the template allows for internal contributors but which is unclear for an outside contributor. The lint/typecheck/test/build checklist item is unchecked, and the description says these were not reported as passing. The Linked Issue reference is present.
Resolution
Optional: fill in the AI Disclosure section if an AI model was used, or confirm the author is a StablyAI team member. Either check the pnpm lint, typecheck, test, and build item or state why it is still open.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Initialize selecting from the selection the press creates.
The onDidChangeCursorSelection subscription starts inside the onMouseDown callback. Monaco applies the press's selection before it emits public onMouseDown. A Shift-press that extends the selection therefore fires its selection event before this listener exists, and selecting stays false.
If the drag then keeps the pointer on the same model position, the selection does not change and no further event fires. While the pointer stays inside the pane, line 107 returns on each frame, so auto-scroll does not start while the pointer holds at the edge. Moving to another line sets selecting and restores scrolling.
Read the selection that exists when the listener starts:
Suggested fix
--- "a/src/renderer/src/components/editor/notebook/cells/ipynb-selection-scroll.ts"+++ "b/src/renderer/src/components/editor/notebook/cells/ipynb-selection-scroll.ts"@@ -54,7 +54,8 @@
const controller = new AbortController()
let pointer: PointerEvent | undefined
- let selecting = false+ const initialSelection = editor.getSelection()+ let selecting = !!initialSelection && !initialSelection.isEmpty()
let frame = 0
let lastTime = 0
let scrolledAtY: number | undefined
Committable suggestion
IMPORTANT
Review the replacement and indentation, then test before committing.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Check pane containment before applying the replay inset.
With pane={top:100.5,bottom:900.5} and clientY=101, the pointer is inside the pane, but y becomes 101.5. This condition fails, and the shared helper produces an upward scroll step. An active selection can therefore scroll while the pointer remains on the first visible pixel. (raw.githubusercontent.com)
Check the original clientY against the pane bounds. Keep the one-pixel clamp separate for replay. Add a fractional-boundary regression case.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Pointers below a pane shorter than 24 px can scroll the notebook upward.
The shared helper tests the top edge before the bottom edge. When the notebook pane is shorter than 24 px, the top-edge band extends below the pane. A pointer below the pane in that band receives a negative step. The scroll handler then scrolls the notebook up if the cell starts above the header. Because getIpynbSelectionScroll passes the pane height through unchanged, this can occur in a small notebook layout.
A pointer below the pane must not produce an upward scroll. Ensure the below-pane case yields a non-negative step, or prevent the pane from being shorter than 24 px. Changing the shared helper also changes the diff-comment drag behavior, so keep that behavior unchanged.
… the pane
Notebook code and Markdown cells are sized to their content, so Monaco
never scrolls internally and its own drag edge-scroll only starts once the
pointer leaves the (taller, clipped) editor node. The notebook's overflow
root had no drag autoscroll, so a selection stopped at the last visible line.
While a left-button text selection drag is held past the pane's top
(sticky header) or bottom edge, scroll the notebook root each frame with
the shared drag autoscroll step and replay the held pointer at a y clamped
into the pane so Monaco extends the selection to the newly visible line.
Capped (>200 line) cells fall back to Monaco's inner scroll once the
notebook reaches the cell edge. Scrolling never starts inside the pane, so
double-clicks and in-pane drags behave as before.
Fixesstablyai#51757
Co-authored-by: Neil <[email protected]>
nwparker
changed the title
fix(notebook): scroll while extending a text selection in a cell (Jupyter Notebook)
fix(notebook): scroll the notebook while a cell selection drag leaves the pane
Nov 28, 2026
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
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.
ELI5
In a Jupyter notebook, if you click inside a cell and drag down (or up) to select text, the notebook now scrolls with you once your pointer goes past the bottom (or top) of the pane, and the selection keeps growing. Before, the selection stopped at the last line you could see.
What Changed
overflow-autoroot had no drag autoscroll.ipynb-selection-scroll.ts, installed once per active cell editor. A content mousedown adds window pointer listeners (capture) and runs a rAF loop that scrolls the notebook root using the sharedgetDragAutoScrollStepPx.IpynbVieweraddsdata-ipynb-viewportanddata-ipynb-headerhooks so the helper can find the scroll root and the sticky header.Why
Native selection autoscroll can't help here because Monaco
preventDefaults the mousedown. Making cells scroll internally would break the content-sized notebook layout. Replaying the held pointer through Monaco's own drag handler keeps its selection semantics (word/line modes, Shift, Escape, text-move rules). We only add the outer scroll, the same way Monaco'sTopBottomDragScrollingreplays its last mouse event every frame.Linked Issue
Fixes #51757
Visual Proof
Recorded in a hidden Electron e2e build on a remote macOS machine. A 100-line code cell in a 940 px pane: press on line 4, drag past the pane bottom and hold.
Before (main): the notebook does not scroll and the selection stops at the edge line.
51764-before.webm
After: the notebook scrolls and the selection follows to the cell end.
51764-after.webm
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
ipynb-selection-scroll.test.tsis a pure unit test of the pane-edge gate and clamp helper. It checks:It fails against the earlier in-band gate. The drag and scroll wiring needs real Monaco and real pointer events, so it was proven with hidden-Electron e2e scratch specs on macOS instead of a committed UI test.
Reproduced on main: scrollTop stays 0 -> 0 and the cursor stays stuck on the edge line (42) for the whole hold.
With the fix:
Static gates pass on the touched files:
oxlint,oxfmt --check, anti-slop oxlint, code-quality native and type-aware oxlint, ast-grep, andcheck-changed-code-quality.mjs.Platforms: macOS runtime. The change is renderer-only. On Linux, pointer capture fails and Monaco listens on window, and the bubbling replay still reaches it (checked against Monaco 0.55.1 source). SSH and remote workspaces use the same renderer path.
Performance
This only runs while a left-button selection drag is held after a press on cell text. There are no listeners otherwise, and no polling, timers, I/O, IPC or subprocesses.
ScriptDurationover a 900 ms edge hold (about 55 frames at 60 Hz) on macOS:Risk
Level: Low
The riskiest part is the synthetic
pointermovereplay into Monaco's drag. If Monaco stops handling it (for example after a Monaco upgrade), the loop stops at the first refused replay, and the notebook falls back to today's behavior of not scrolling. The change is renderer-only, with no saved data or settings. A plain revert backs it out.Review
Reviewed for correctness, security and performance.
Agent skill upstream boundary
Notes
Covers selection within a single cell (no cross-cell selection). No security, mobile or backwards-compatibility impact.
Original fix by @dzkchen in #51764. Their authorship is preserved on the commit.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)