[Bug] /explorer: leaving a search strands the selection outside the list, no highlight, Up/Enter inert, Down teleports to the last row
Description
/explorer swaps its rendered list between every matching node in the whole tree (search mode) and only the currently-expanded nodes (tree mode), but selectedIndex is only ever clamped inside the arrow-key handlers, never re-clamped when the underlying list itself shrinks out from under it. Exiting search restores the short tree list while selectedIndex still points at wherever it was left in the much longer search-results list.
Parent: #907
Steps to Reproduce
- Run
/explorer. - Press
/to enter search mode, then type a common letter (e.g.e) so it matches many files across the tree. - Press Down repeatedly (15-20+ times) to move deep into the search results.
- Press Esc to leave search and return to tree mode.
- Press Down once more.
Expected Behavior
Leaving search either keeps a sensible selection (e.g. clamped to the last valid row, or reset to a stable position) with a visible highlight, and normal navigation continues to work.
Actual Behavior
Immediately after Esc: no row is highlighted anywhere in the list, and the path readout at the bottom of the panel goes blank the explorer looks frozen/unresponsive. Pressing Down once then teleports straight to the very last item in the entire tree, skipping over everything in between. Up and Enter are inert in the stranded state (Enter no-ops because the selected node resolves to undefined).
Recording
Root Cause
source/components/file-explorer/index.tsx:
filteredList(line 111) is a different array depending onsearchModethe full tree when searching, only expanded nodes otherwise.selectedNode(line 134):filteredList[selectedIndex]?.nodesilentlyundefinedonceselectedIndexexceeds the new, shorter list.- Nothing re-clamps
selectedIndexwhenfilteredListitself changes length (e.g. on the search→tree mode transition) only the arrow-key handlers clamp it, and only against whatever list is current at that keypress.
Suggested Fix
Re-clamp selectedIndex whenever filteredList changes e.g. a useEffect keyed on filteredList.length that clamps selectedIndex to Math.min(selectedIndex, filteredList.length - 1), or compute the clamped value at read time instead of only inside the key handlers.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs on the latest
main
Hey @akramcodez, could you assign this to me ?
Picking this up - a fix will follow shortly.