Skip to content

Commit 7e37cec

Browse files
authored
Fix hardcoded context menu index for File option selection (RooCodeInc#4065)
* Fix hardcoded context menu index for File option selection The ChatTextArea component was using a hardcoded index 3 to select the "File" option by default in the context menu, but this was incorrect - the File option is actually at index 5 in the menu options array. This caused the wrong option (Git) to be selected by default when pressing Escape or when no query is provided. Additionally, the hardcoded approach was fragile and would break if the context menu order changed in the future. Key changes: - Added `DEFAULT_CONTEXT_MENU_OPTIONS` array in context-mentions.ts to define the canonical menu order - Added helper function `getDefaultContextMenuOptionIndex()` dynamically finds the correct index for any option type - Updated ChatTextArea to use `DEFAULT_CONTEXT_MENU_OPTION` constant instead of hardcoded 3 - Updated `getContextMenuOptions()` to use the new centralized array * changeset
1 parent b0926b1 commit 7e37cec

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

.changeset/rare-ducks-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": minor
3+
---
4+
5+
Context menu is default to File option on start up

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { FileServiceClient, StateServiceClient } from "@/services/grpc-client"
1010
import {
1111
ContextMenuOptionType,
1212
getContextMenuOptions,
13+
getContextMenuOptionIndex,
1314
insertMention,
1415
insertMentionDirectly,
1516
removeMention,
@@ -60,6 +61,9 @@ const getImageDimensions = (dataUrl: string): Promise<{ width: number; height: n
6061
})
6162
}
6263

64+
// Set to "File" option by default
65+
const DEFAULT_CONTEXT_MENU_OPTION = getContextMenuOptionIndex(ContextMenuOptionType.File)
66+
6367
interface ChatTextAreaProps {
6468
inputValue: string
6569
activeQuote: string | null
@@ -530,7 +534,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
530534
if (event.key === "Escape") {
531535
// event.preventDefault()
532536
setSelectedType(null)
533-
setSelectedMenuIndex(3) // File by default
537+
setSelectedMenuIndex(DEFAULT_CONTEXT_MENU_OPTION)
534538
return
535539
}
536540

@@ -770,7 +774,7 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
770774
})
771775
}, 200) // 200ms debounce
772776
} else {
773-
setSelectedMenuIndex(3) // Set to "File" option by default
777+
setSelectedMenuIndex(DEFAULT_CONTEXT_MENU_OPTION)
774778
}
775779
} else {
776780
setSearchQuery("")

webview-ui/src/utils/context-mentions.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ export interface ContextMenuQueryItem {
7575
description?: string
7676
}
7777

78+
const DEFAULT_CONTEXT_MENU_OPTIONS = [
79+
ContextMenuOptionType.URL,
80+
ContextMenuOptionType.Problems,
81+
ContextMenuOptionType.Terminal,
82+
ContextMenuOptionType.Git,
83+
ContextMenuOptionType.Folder,
84+
ContextMenuOptionType.File,
85+
]
86+
87+
export function getContextMenuOptionIndex(option: ContextMenuOptionType) {
88+
return DEFAULT_CONTEXT_MENU_OPTIONS.findIndex((item) => item === option)
89+
}
90+
7891
export function getContextMenuOptions(
7992
query: string,
8093
selectedType: ContextMenuOptionType | null = null,
@@ -114,14 +127,7 @@ export function getContextMenuOptions(
114127
return commits.length > 0 ? [workingChanges, ...commits] : [workingChanges]
115128
}
116129

117-
return [
118-
{ type: ContextMenuOptionType.URL },
119-
{ type: ContextMenuOptionType.Problems },
120-
{ type: ContextMenuOptionType.Terminal },
121-
{ type: ContextMenuOptionType.Git },
122-
{ type: ContextMenuOptionType.Folder },
123-
{ type: ContextMenuOptionType.File },
124-
]
130+
return DEFAULT_CONTEXT_MENU_OPTIONS.map((type) => ({ type }))
125131
}
126132

127133
const lowerQuery = query.toLowerCase()

0 commit comments

Comments
 (0)