[Bug] @file mention autocomplete highlight vanishes past the 5th item, so Tab can insert a file that was never shown
Description
The @file mention autocomplete list only ever renders the first 5 matches (fileCompletions.slice(0, 5)), but Up/Down navigation wraps over the entire match list (up to 20 results), with no scroll window on the visible slice. Once the selected index moves past 4, the highlight marker has nothing to attach to the visible list looks completely unselected while the real selection keeps moving invisibly through items the user never sees.
Parent: #907
Steps to Reproduce
- In a project with more than 5 files matching a prefix, type
@followed by a partial path that matches 6+ files (e.g.@src/component). - Press Down arrow 6+ times.
- Press Tab.
Expected Behavior
Either the visible list scrolls to keep the highlighted item on screen (like the sibling slash-command completion list does, with a "Showing X-Y of Z" indicator), or navigation is bounded to the 5 visible items.
Actual Behavior
After the 5th Down press, the ▸ highlight marker disappears from every visible row the list appears static and unselected. Pressing Tab then inserts a file that was never shown on screen at all: in a live reproduction with 8 matching files, pressing Down 7 times and Tab inserted @src/component8.tsx, even though only component1.tsx–component5.tsx ever appeared in the rendered list.
Recording
Root Cause
source/components/user-input.tsx:
- Render always slices to the first 5 (line 1255):
{fileCompletions.slice(0, 5).map((file, index) => (...the localindexhere never exceeds 4. - Navigation wraps over the full list, not the visible slice (Up ~line 1049, Down ~line 1074):
setSelectedFileIndex(prev => prev < fileCompletions.length - 1 ? prev + 1 : 0). - Selection on Tab (line 512):
const selectedPath = fileCompletions[selectedFileIndex]?.path;reads whateverselectedFileIndexcurrently is, regardless of whether it was ever rendered.
getFileCompletions (source/utils/file-autocomplete.ts) returns up to 20 matches, so this is easily reachable in any project with more than 5 files sharing a prefix.
Suggested Fix
Give the file-mention list the same windowed rendering the slash-command completion list already has: compute a visible window around selectedFileIndex (e.g. commandCompletionWindow pattern) instead of a hardcoded slice(0, 5), and show a "X of Y" indicator when the list is longer than the window.
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, I’m interested in taking this one up. I’ve already worked on it locally, could you assign it to me?