Skip to content

fix(filepicker): keep the selection valid while entries load - #1093

Open
janearc wants to merge 1 commit into
charmbracelet:mainfrom
janearc:fix/filepicker-navigation-before-load
Open

janearc wants to merge 1 commit into
charmbracelet:mainfrom
janearc:fix/filepicker-navigation-before-load

Conversation

@janearc

@janearc janearc commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Pressing Down, G, or Page Down before directory entries arrive can set the selection to -1. Keep it at zero while the list is empty so Enter can select the first file once it loads.

Add tests for navigation before loading completes and for normal selection and navigation after loading.

  • [👩🏻‍🎤] I have read CONTRIBUTING.md.
  • [🚳] I have created a discussion that was approved by a maintainer (for new features).

fix(filepicker): keep selection valid before entries load

Pressing Down, G, or PageDown before directory entries arrive can leave the selection at -1, and Enter then indexes outside the entries. Keep the empty selection at zero until entries exist. The regression sends keys before loading completes.

Open #963 changes the default height for #864; it does not clamp a negative selection while directory entries are pending. This fix leaves height behavior unchanged.

Separate tests cover positive behavior (TestLoadedPickerSelectsFile), negative controls (TestLoadedPickerDoesNotNavigatePastLastEntry), and the regression (TestKeysBeforeEntriesLoad). A representative regression fails on unchanged main and passes with the fix. The positive control passes on main; a deliberate break is also caught by the negative test.

Validation on owner main 1deada954e6e, Go 1.26.10:

  • Full native arm64 race suite passes (-count=1 -cpu=1,4), plus 20 focused race repetitions.
  • Full amd64 tests and race suite pass under Rosetta.
  • Exact CI-pinned golangci-lint v2.13.1, formatting, vet and module tidy pass. Module files are unchanged.
  • Linux/Windows 386 (i386), amd64 and arm64, plus Darwin amd64: build, all-package test compilation, vet and configured lint pass.
  • Aggregate root-module statement coverage: 55.9557% (1818/3249) → 56.5097% (1836/3249); it does not decrease.

Cross-target binaries were compiled rather than executed. These are local results; remote CI remains to be confirmed.

disclosure: one of a bunch of things that popped up whenworking on my own. harness. i use claude, claude root-caused. them, including this one. i reviewed this (it's a very narrow patch, so should just go in easily, tests are clean, low risk, etc, simple bug). i also asked codex to review it so that we weren't just taking claude's word on. things and while we were doing. it qwen had a look and instead told me to use rust. sometimes it's just like that.

Pressing Down, G, or Page Down before directory entries arrive can
set the selection to -1. Keep it at zero while the list is empty so
Enter can select the first file once it loads.

Add tests for navigation before loading completes and for normal
selection and navigation after loading.
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