Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dirty-plants-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Now items in the Chat context menu will not be auto selected if your cursor is already on the row when the items change
31 changes: 28 additions & 3 deletions webview-ui/src/components/chat/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ interface ContextMenuProps {
commands?: Command[]
}

const EMPTY_COMMANDS: Command[] = [] // kilocode_change - maintain stable references for React props
const EMPTY_SEARCH_RESULTS: SearchResult[] = [] // kilocode_change - maintain stable references for React props

const ContextMenu: React.FC<ContextMenuProps> = ({
onSelect,
searchQuery,
Expand All @@ -41,8 +44,8 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
selectedType,
queryItems,
modes,
dynamicSearchResults = [],
commands = [],
dynamicSearchResults = EMPTY_SEARCH_RESULTS, // kilocode_change
commands = EMPTY_COMMANDS, // kilocode_change
}) => {
const [materialIconsBaseUri, setMaterialIconsBaseUri] = useState("")
const menuRef = useRef<HTMLDivElement>(null)
Expand All @@ -51,6 +54,22 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
return getContextMenuOptions(searchQuery, selectedType, queryItems, dynamicSearchResults, modes, commands)
}, [searchQuery, selectedType, queryItems, dynamicSearchResults, modes, commands])

// kilocode_change start - disable hover selection briefly when items change to prevent accidental selections
const [allowSelection, setAllowSelection] = useState(false)
const prevOptionsRef = useRef<ContextMenuQueryItem[] | null>(null)

useEffect(() => {
if (prevOptionsRef.current === null || filteredOptions !== prevOptionsRef.current) {
setAllowSelection(false)
const timer = setTimeout(() => {
setAllowSelection(true)
}, 100)
return () => clearTimeout(timer)
}
prevOptionsRef.current = filteredOptions
}, [filteredOptions])
// kilocode_change end - disable hover selection briefly when items change to prevent accidental selections

useEffect(() => {
if (menuRef.current) {
const selectedElement = menuRef.current.children[selectedIndex] as HTMLElement
Expand Down Expand Up @@ -373,7 +392,13 @@ const ContextMenu: React.FC<ContextMenuProps> = ({
}
: {}),
}}
onMouseEnter={() => isOptionSelectable(option) && setSelectedIndex(index)}>
onMouseEnter={() => {
// kilocode_change start - add allowEvents check
if (allowSelection && isOptionSelectable(option)) {
setSelectedIndex(index)
}
// kilocode_change end - add allowEvents check
}}>
<div
style={{
display: "flex",
Expand Down