Skip to content

Keep the :ctx picker's cursor on screen when the context list is long - #11

Merged
pierreneter merged 1 commit into
p10node:mainfrom
p3rsephone:ctx-picker-scroll
Oct 22, 2026
Merged

pierreneter merged 1 commit into
p10node:mainfrom
p3rsephone:ctx-picker-scroll

Conversation

@p3rsephone

Copy link
Copy Markdown

With more contexts than fit in the main panel, the :ctx picker does not scroll. The arrow keys move the cursor, but the list always draws from the first context, so the highlighted row goes off the bottom of the screen and enter switches to a context you cannot see. The picker opens on the current context, so when that one sorts below the fold (k10s-demo after a long kubeconfig) nothing is highlighted at all. The demo legend under the list is cut off too.

contextBody is given the number of rows the panel has, but it ignored it: it rendered every context and Panel dropped the lines that did not fit. It now draws only the rows that fit, centred on the cursor the way the theme picker does it, and keeps the header and the legend in view. Click zones need no change: bubblezone drops the zones of rows that are no longer drawn.

Before

2026-10-16 18 44 31

After

2026-10-16 19 12 55

Tests

Tests in internal/ui/ctxpicker_test.go, with 60 extra contexts on a 44-row screen:

  • TestContextPickerKeepsTheCursorOnScreen: the highlighted row is on screen after moving down past the fold, at the end of the list, and back at the top.
  • TestContextPickerOpensOnACurrentContextBelowTheFold: the picker opens on k10s-demo after /demo, and that row is on screen.
  • TestContextPickerKeepsTheLegendWithALongList: the demo legend is still drawn.

All three fail on main. Checked with gofmt, go vet ./... and go test ./... on Go 1.27.2 and also 1.26.9. I also ran a build of this branch with a kubeconfig of 40 contexts in a 30-row terminal, and the cursor stays in view.

@pierreneter

Copy link
Copy Markdown
Member

Nice catch, and thanks for the thorough write-up. I'd never hit this with my short kubeconfig, but the "enter switches to a context you can't see" part is nasty. Glad it's gone.

Pulled the branch and poked at it a bit. The three tests do fail on main and pass here, and the row math lines up with what Panel gets, so nothing falls off the bottom anymore. Your point about bubblezone dropping undrawn zones is right too, I double-checked the manager code.

Tiny thing, not worth a round trip: the comment about the right-hand label ended up above the loop instead of next to the gap bit. I'll nudge it later.

Merging now. The before/after screenshots made this an easy review.

@pierreneter
pierreneter merged commit d088431 into p10node:main Oct 22, 2026
1 check passed
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.

2 participants