Skip to content

fix: keep the keyboard focus on the same item across a list rebuild - #1979

Open
chris-010 wants to merge 1 commit into
pop-os:masterfrom
chris-010:fix/keep-keyboard-focus-across-list-rebuild
Open

fix: keep the keyboard focus on the same item across a list rebuild#1979
chris-010 wants to merge 1 commit into
pop-os:masterfrom
chris-010:fix/keep-keyboard-focus-across-list-rebuild

Conversation

@chris-010

@chris-010 chris-010 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Steps to reproduce

  1. Select an item in a folder — the second entry, say.
  2. Create a folder that sorts before it (aaa will do).
  3. Press .

The first arrow-down does nothing visible, and the arrow-up after it looks like it skips an entry.

Cause

Tab::select_focus is an index into items_opt. set_items carries the selection over by location_opt but never recomputes that index, so it points at the neighbour once an entry is inserted before the focused one. select_focus_scroll reads the same stale index, so ScrollToFocused scrolls to the wrong row too.

Fix

Remember the focused item's location before the swap and look it up again, the way the selection itself already is.

Testing

Build of 5bdfffa with only this patch: select nnn among six entries, create aab then moves immediately and returns exactly one entry. In daily use here since.

Rebased onto 3aa55b0 since. The rebase is clean and the inserted lines are unchanged; set_items, select_focus and location_opt are untouched by the commits in between, as are all three call sites of set_items. cargo test passes with no default features, with defaults, and with all features.

  • I have disclosed use of any AI generated code in my commit messages.
  • I understand these changes in full and will be able to respond to review comments.
  • My change is accurately described in the commit message.
  • My contribution is tested and working as described.
  • I have read the Developer Certificate of Origin and certify my contribution under its conditions.

Tab::select_focus is an index into items_opt. Tab::set_items carries the
selection over to the new list by location (item.location_opt), but the
index is never recomputed, so it points at the neighbour as soon as an
entry is inserted before the focused one.

Creating a folder that sorts before the selected item is enough to hit
it. Measured with a probe build: the selected item moved from index 1 to
index 2 while select_focus stayed at 1. The first arrow-down then
appears to do nothing -- it moves onto the item that is already
selected -- and arrow-up afterwards looks like it skips one.

The same stale index is read by select_focus_scroll, which
Message::ScrollToFocused uses. That message is dispatched by TabRescan
whenever selection_paths is set, i.e. right after creating an item, so
the view also scrolls to the wrong row.

The focused item's location is remembered before the swap and looked up
again in the new list, which is exactly how the selection itself is
already carried over.

Drafted with AI assistance (Claude Code); the change was reviewed,
built and tested by me on real hardware as described.

Signed-off-by: chris-010 <10660568+chris-010@users.noreply.github.com>
@chris-010
chris-010 force-pushed the fix/keep-keyboard-focus-across-list-rebuild branch from 92f1bcf to 15d1f2d Compare August 20, 2026 12:35
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.

1 participant