nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] /explorer: leaving a search strands the selection outside the list, no highlight, Up/Enter inert, Down teleports to the last row

Open addyCooks opened this issue 2 months ago • 2 comments

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

  1. Run /explorer.
  2. Press / to enter search mode, then type a common letter (e.g. e) so it matches many files across the tree.
  3. Press Down repeatedly (15-20+ times) to move deep into the search results.
  4. Press Esc to leave search and return to tree mode.
  5. 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

Image

Root Cause

source/components/file-explorer/index.tsx:

  • filteredList (line 111) is a different array depending on searchMode the full tree when searching, only expanded nodes otherwise.
  • selectedNode (line 134): filteredList[selectedIndex]?.node silently undefined once selectedIndex exceeds the new, shorter list.
  • Nothing re-clamps selectedIndex when filteredList itself 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

addyCooks avatar Sep 23 '26 11:09 addyCooks

Hey @akramcodez, could you assign this to me ?

addyCooks avatar Sep 23 '26 11:09 addyCooks

Picking this up - a fix will follow shortly.

awhite0030 avatar Sep 23 '26 13:09 awhite0030