Skip to content

fix: browser cursor resets to top when switching tabs #173

@oobagi

Description

@oobagi

Problem

When switching between the Notebooks and Recents tabs with Tab, the cursor always resets to position 0. If you're on the 5th notebook and press Tab to check recents, then Tab back, you're back at the top instead of where you left off.

Context

The tab handler in internal/browser/browser.go line 362 unconditionally sets m.cursor = 0:

case "tab":
    if m.level == 0 {
        m.recentsView = !m.recentsView
        m.cursor = 0  // <-- always resets

The model already has savedCursor for L0→L1 transitions but nothing for tab switching.

Fix

Add a savedRecentsCursor int field to the Model. When switching tabs, save the current cursor and restore the saved one for the target tab.

case "tab":
    if m.level == 0 {
        if m.recentsView {
            m.savedRecentsCursor = m.cursor
            m.cursor = m.savedCursor  // reuse existing field for notebooks cursor
        } else {
            m.savedCursor = m.cursor
            m.cursor = m.savedRecentsCursor
        }
        m.recentsView = !m.recentsView

Clamp restored cursor to list bounds after loading in case items were removed.

File: internal/browser/browser.go

Tasks

  • Add savedRecentsCursor int to Model struct
  • Save/restore cursor on tab switch
  • Clamp restored cursor to list length after load completes
  • Verify cursor persists across multiple tab switches

Test plan

  • Navigate to 5th notebook → Tab → Tab back → cursor is on 5th notebook
  • Navigate to 3rd recent → Tab → Tab back → cursor is on 3rd recent
  • Delete a recent so list shrinks → Tab back → cursor clamped, no crash

Scope

Type: bug
Size: small

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions