Skip to content

feat(vim): zz/zt/zb scroll for notebook viewport (#9701)#9728

Open
LioSergent wants to merge 1 commit into
marimo-team:mainfrom
LioSergent:vim-zz
Open

feat(vim): zz/zt/zb scroll for notebook viewport (#9701)#9728
LioSergent wants to merge 1 commit into
marimo-team:mainfrom
LioSergent:vim-zz

Conversation

@LioSergent
Copy link
Copy Markdown
Contributor

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

  • [ ] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable). => not a large change.
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • [ ] Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes. => I don't think this is worthy of documentation change as no API change and this expected vim behavior.
  • Tests have been added for the changes made. => No test, but other Vim actions are not tested either.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 29, 2026 5:26pm

Request Review

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.
@LioSergent LioSergent marked this pull request as ready for review May 29, 2026 17:33
@kirangadhave kirangadhave self-requested a review May 30, 2026 00:57
@kirangadhave kirangadhave added the enhancement New feature or request label May 30, 2026
@kirangadhave
Copy link
Copy Markdown
Member

Can you please add a video which demos the new behavior?

@kirangadhave kirangadhave requested a review from Copilot May 30, 2026 01:03
@kirangadhave
Copy link
Copy Markdown
Member

@cubic-dev-ai

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented May 30, 2026

@cubic-dev-ai

@kirangadhave I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Re-trigger cubic

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 scrollCursorTo helper to compute cursor coordinates and scroll #App.
  • Maps Vim normal-mode zz, zt, and zb to center/top/bottom viewport scrolling actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zz vim-mode scroll for notebook viewport

3 participants