feat(vim): zz/zt/zb scroll for notebook viewport (#9701)#9728
Open
LioSergent wants to merge 1 commit into
Open
feat(vim): zz/zt/zb scroll for notebook viewport (#9701)#9728LioSergent wants to merge 1 commit into
LioSergent wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Override the built-in no-op zz/zt/zb vim commands (which target CodeMirror's own scroll container, unused in marimo) to instead scroll the current in-cell cursor to the center/top/bottom of the notebook viewport.
Member
|
Can you please add a video which demos the new behavior? |
Member
Contributor
|
@kirangadhave I have started the AI code review. It will take a few minutes to complete. |
Contributor
There was a problem hiding this comment.
No issues found across 1 file
Architecture diagram
sequenceDiagram
participant User as User
participant CodeMirror as CodeMirror Editor
participant Vim as Vim Keymap Plugin
participant scrollCursorTo as scrollCursorTo()
participant DOM as DOM (#App element)
Note over User,DOM: Vim scroll commands for notebook viewport
User->>CodeMirror: Press zz/zt/zb
CodeMirror->>Vim: Keydown event (normal mode)
Vim->>Vim: Lookup mapped command
alt zz
Vim->>scrollCursorTo: Execute action "scrollCursorToCenter"
scrollCursorTo->>scrollCursorTo: position = "center"
else zt
Vim->>scrollCursorTo: Execute action "scrollCursorToTop"
scrollCursorTo->>scrollCursorTo: position = "start"
else zb
Vim->>scrollCursorTo: Execute action "scrollCursorToBottom"
scrollCursorTo->>scrollCursorTo: position = "end"
end
Note over scrollCursorTo,DOM: Get cursor position in viewport
scrollCursorTo->>CodeMirror: cm.cm6 view reference
CodeMirror-->>scrollCursorTo: view object
scrollCursorTo->>CodeMirror: view.coordsAtPos(selection.main.head)
CodeMirror-->>scrollCursorTo: cursor coordinates (top, bottom)
Note over scrollCursorTo,DOM: Calculate scroll offset
scrollCursorTo->>DOM: document.getElementById("App")
DOM-->>scrollCursorTo: app element
scrollCursorTo->>DOM: appEl.clientHeight (viewport height)
alt position = center
scrollCursorTo->>scrollCursorTo: delta = (coords.top + coords.bottom) / 2 - viewportHeight / 2
else position = start
scrollCursorTo->>scrollCursorTo: delta = coords.top
else position = end
scrollCursorTo->>scrollCursorTo: delta = coords.bottom - viewportHeight
end
Note over scrollCursorTo,DOM: Smooth scroll the notebook viewport
scrollCursorTo->>DOM: appEl.scrollBy({ top: delta, behavior: "smooth" })
DOM-->>scrollCursorTo: Scroll executed
rect rgba(255, 255, 255, 0.1)
Note over scrollCursorTo: Guard clauses (no-op paths)
alt cm.cm6 view is null
scrollCursorTo->>scrollCursorTo: return (no-op)
else cursor coords are null
scrollCursorTo->>scrollCursorTo: return (no-op)
else #App element not found
scrollCursorTo->>scrollCursorTo: return (no-op)
end
end
Contributor
There was a problem hiding this comment.
Pull request overview
Adds custom Vim scroll commands so zz, zt, and zb scroll the active CodeMirror cursor within marimo’s notebook viewport instead of CodeMirror’s unused internal scroll container.
Changes:
- Adds
scrollCursorTohelper to compute cursor coordinates and scroll#App. - Maps Vim normal-mode
zz,zt, andzbto center/top/bottom viewport scrolling actions.
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.
Override the built-in no-op zz/zt/zb vim commands (which target CodeMirror's own scroll container, unused in marimo) to instead scroll the current in-cell cursor to the center/top/bottom of the notebook viewport.
📝 Summary
Closes #9701
📋 Pre-Review Checklist
✅ Merge Checklist