diff --git a/src/components/ai-chat/ai-chat-input-bar.tsx b/src/components/ai-chat/ai-chat-input-bar.tsx index 806cf848..d60fedc1 100644 --- a/src/components/ai-chat/ai-chat-input-bar.tsx +++ b/src/components/ai-chat/ai-chat-input-bar.tsx @@ -156,7 +156,8 @@ const AIChatInputBar = memo(function AIChatInputBar({ if (mentionState.active) { if (e.key === "ArrowDown") { e.preventDefault(); - selectNext(); + const filteredFiles = getFilteredFiles(allProjectFiles); + selectNext(filteredFiles.length); } else if (e.key === "ArrowUp") { e.preventDefault(); selectPrevious(); diff --git a/src/stores/ai-chat/store.ts b/src/stores/ai-chat/store.ts index cdcf90c5..fecc208c 100644 --- a/src/stores/ai-chat/store.ts +++ b/src/stores/ai-chat/store.ts @@ -412,9 +412,10 @@ export const useAIChatStore = create()( state.mentionState.position = position; }), - selectNext: () => + selectNext: (totalItems: number) => set((state) => { - state.mentionState.selectedIndex = Math.min(state.mentionState.selectedIndex + 1, 4); + const maxIndex = Math.max(totalItems - 1, 0); + state.mentionState.selectedIndex = Math.min(state.mentionState.selectedIndex + 1, maxIndex); }), selectPrevious: () => diff --git a/src/stores/ai-chat/types.ts b/src/stores/ai-chat/types.ts index 7cd9e10b..444ea9f1 100644 --- a/src/stores/ai-chat/types.ts +++ b/src/stores/ai-chat/types.ts @@ -74,7 +74,7 @@ export interface AIChatActions { hideMention: () => void; updateSearch: (search: string) => void; updatePosition: (position: { top: number; left: number }) => void; - selectNext: () => void; + selectNext: (totalItems: number) => void; selectPrevious: () => void; setSelectedIndex: (index: number) => void; getFilteredFiles: (allFiles: FileEntry[]) => FileEntry[];