Skip to content

Commit 6e1f1f0

Browse files
committed
Fix hard-coded index bound in mention dropdown navigation
https://claude.ai/code/session_01PwR8J37gjzpQ1tEbEJUgTi
1 parent d31cc29 commit 6e1f1f0

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/components/ai-chat/ai-chat-input-bar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ const AIChatInputBar = memo(function AIChatInputBar({
156156
if (mentionState.active) {
157157
if (e.key === "ArrowDown") {
158158
e.preventDefault();
159-
selectNext();
159+
const filteredFiles = getFilteredFiles(allProjectFiles);
160+
selectNext(filteredFiles.length);
160161
} else if (e.key === "ArrowUp") {
161162
e.preventDefault();
162163
selectPrevious();

src/stores/ai-chat/store.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,10 @@ export const useAIChatStore = create<AIChatState & AIChatActions>()(
412412
state.mentionState.position = position;
413413
}),
414414

415-
selectNext: () =>
415+
selectNext: (totalItems: number) =>
416416
set((state) => {
417-
state.mentionState.selectedIndex = Math.min(state.mentionState.selectedIndex + 1, 4);
417+
const maxIndex = Math.max(totalItems - 1, 0);
418+
state.mentionState.selectedIndex = Math.min(state.mentionState.selectedIndex + 1, maxIndex);
418419
}),
419420

420421
selectPrevious: () =>

src/stores/ai-chat/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface AIChatActions {
7474
hideMention: () => void;
7575
updateSearch: (search: string) => void;
7676
updatePosition: (position: { top: number; left: number }) => void;
77-
selectNext: () => void;
77+
selectNext: (totalItems: number) => void;
7878
selectPrevious: () => void;
7979
setSelectedIndex: (index: number) => void;
8080
getFilteredFiles: (allFiles: FileEntry[]) => FileEntry[];

0 commit comments

Comments
 (0)