Skip to content

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

Merged
kirangadhave merged 1 commit into
marimo-team:mainfrom
LioSergent:vim-zz
Jun 1, 2026
Merged

feat(vim): zz/zt/zb scroll for notebook viewport (#9701)#9728
kirangadhave merged 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

vercel Bot commented May 29, 2026

Copy link
Copy Markdown

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 Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai

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

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

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

zz-motion
@kirangadhave

Copy link
Copy Markdown
Member

Thanks @LioSergent, looks great. Merging this now.

@kirangadhave kirangadhave merged commit 739276d into marimo-team:main Jun 1, 2026
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

3 participants