Skip to content

Add Shift+0-9 percentage seeking (#183)#186

Merged
bjarneo merged 2 commits intobjarneo:mainfrom
goutham80808:main
Apr 19, 2026
Merged

Add Shift+0-9 percentage seeking (#183)#186
bjarneo merged 2 commits intobjarneo:mainfrom
goutham80808:main

Conversation

@goutham80808
Copy link
Copy Markdown
Contributor

@goutham80808 goutham80808 commented Apr 19, 2026

Closes #183
Implements YouTube-style percentage seeking via Shift+0-9.

  • Shift+0 seeks to 0% (start), Shift+5 to 50%, Shift+9 to 90%
  • Uses shifted symbol matching to work across keyboard layouts
    (US, Nordic, etc.) since terminals translate modifier keys before
    Bubbletea sees them
  • Added keymap entry for discoverability
  • No conflict with existing keybindings - text overlays (search,
    jump mode, URL input) intercept keys first

Development notes

Approach 1: msg.Mod + msg.Code (didn't work)

Tried checking msg.Mod&tea.ModShift != 0 and msg.Code >= '0' && msg.Code <= '9'. This assumed the terminal would set the Shift modifier flag and report the unshifted digit in Code. On Windows, Mod is always 0 - terminals translate Shift+5 into % before Bubbletea sees it.

Approach 2: msg.BaseCode + msg.ShiftedCode (didn't work)

Bubbletea v2 provides BaseCode (physical US-PC101 key) and ShiftedCode fields for layout-independent detection. Tested by printing all key fields to the status bar. Both BaseCode and ShiftedCode are always \x00 on this terminal - not populated.

Debug output revealed:

Bare 5: Code='5' Mod=0 Text="5" Base='\x00' Shifted='\x00'
Shift+5: Code='%' Mod=0 Text="%" Base='\x00' Shifted='\x00'
The terminal handles Shift entirely - it sends the shifted character with no modifier flags.

Approach 3: Shifted symbol matching (final solution)

Since the terminal sends the shifted symbol directly, match msg.Text against a map of shifted-digit symbols (), !, @, #, $, %, ^, &, *, () and map back to digits 0–9. Uses US keyboard layout as reference. Works on any keyboard where Shift+digit produces these symbols.

Summary by CodeRabbit

  • New Features
    • Added keyboard shortcuts (Shift+0-9) to seek to specific percentages of the current track (0% at start, 90% near end).

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 425620f3-da18-4043-a917-d6e08e4bdc61

📥 Commits

Reviewing files that changed from the base of the PR and between b5ba37d and 33e828f.

📒 Files selected for processing (2)
  • ui/model/keymap.go
  • ui/model/keys.go

📝 Walkthrough

Walkthrough

This pull request implements YouTube-style number key seeking. The changes add a pre-switch key handling branch that maps Shift+0-9 input to seek positions (0–90% of track), and update the keymap overlay to display the new keybinding.

Changes

Cohort / File(s) Summary
Keymap Display Update
ui/model/keymap.go
Added Shift+0-9 entry to the displayed key bindings list showing the seek action.
Seek Logic Implementation
ui/model/keys.go
Added pre-switch branch in handleKey that maps shifted symbols to digits 0–9, checks player duration, calculates seek target as duration * digit / 10, and calls seekAbsolute(target).

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant KeyHandler as Key Handler<br/>(handleKey)
    participant Player
    participant SeekLogic as Seek Logic<br/>(seekAbsolute)

    User->>KeyHandler: Press Shift+0-9
    KeyHandler->>KeyHandler: Map shifted symbol to digit (0-9)
    KeyHandler->>Player: Check duration
    Player-->>KeyHandler: Return duration
    
    alt Duration > 0
        KeyHandler->>KeyHandler: Calculate target = duration × digit / 10
        KeyHandler->>SeekLogic: Call seekAbsolute(target)
        SeekLogic-->>KeyHandler: Return seek result
        KeyHandler-->>User: Seek executed
    else Duration ≤ 0
        KeyHandler-->>KeyHandler: No action, fall through
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding Shift+0-9 percentage seeking functionality, matching the PR objectives.
Linked Issues check ✅ Passed The implementation fully addresses issue #183 requirements: Shift+0-9 maps to 0%-90% seeking positions, matching the YouTube-style percentage navigation requested.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the linked issue: keymap entry addition and key handling logic for Shift+0-9 seeking, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Owner

@bjarneo bjarneo left a comment

Choose a reason for hiding this comment

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

Nice

@bjarneo bjarneo merged commit 5eeee34 into bjarneo:main Apr 19, 2026
1 check passed
@bjarneo
Copy link
Copy Markdown
Owner

bjarneo commented Apr 19, 2026

Oh no, I regret it already. There's been a lot of back-and-forth on this, but I really need to nail it. The reason is that my Nordic layout is different than yours, meaning the current mapping is off.

I found a better solution which is something in between. Nj. Meaning 1j, 4j, 10j, means 10% jump. 40% jump. This works very well. Vim style. Give the latest commit a spin.

@goutham80808
Copy link
Copy Markdown
Contributor Author

I really liked your approach to this and loving it. It's working as expected. I had thought of doing n; meaning 1; 2; but out of simplicity I came up with my naive initial approach. But you enlightened me about Nordic layouts and consistency. I really learned a lot. Thanks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add number key seeking like YouTube (0–9 jumps to % of video)

2 participants