Skip to content

Commit 87b6dff

Browse files
committed
feat: add ESC key handling for modes, API provider, and indexing settings popovers
1 parent a824557 commit 87b6dff

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,23 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
440440
})
441441
}, [checkUnsavedChanges])
442442

443+
// Add ESC key handler
444+
useEffect(() => {
445+
const handleKeyDown = (event: KeyboardEvent) => {
446+
if (event.key === "Escape" && open) {
447+
// Use the same logic as clicking outside - check for unsaved changes
448+
handlePopoverClose()
449+
}
450+
}
451+
452+
if (open) {
453+
document.addEventListener("keydown", handleKeyDown)
454+
return () => {
455+
document.removeEventListener("keydown", handleKeyDown)
456+
}
457+
}
458+
}, [open, handlePopoverClose])
459+
443460
const handleSaveSettings = () => {
444461
// Validate settings before saving
445462
if (!validateSettings()) {

webview-ui/src/components/modes/ModesView.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,22 @@ const ModesView = ({ onDone }: ModesViewProps) => {
194194
}
195195
}, [])
196196

197+
// Add ESC key handler for the popover
198+
useEffect(() => {
199+
const handleKeyDown = (event: KeyboardEvent) => {
200+
if (event.key === "Escape" && open) {
201+
setOpen(false)
202+
}
203+
}
204+
205+
if (open) {
206+
document.addEventListener("keydown", handleKeyDown)
207+
return () => {
208+
document.removeEventListener("keydown", handleKeyDown)
209+
}
210+
}
211+
}, [open])
212+
197213
// Handler for clearing search input
198214
const onClearSearch = useCallback(() => {
199215
setSearchValue("")

webview-ui/src/components/ui/searchable-select.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ export function SearchableSelect({
7979
return () => clearTimeout(timeoutId)
8080
}, [value])
8181

82+
// Add ESC key handler
83+
React.useEffect(() => {
84+
const handleKeyDown = (event: KeyboardEvent) => {
85+
if (event.key === "Escape" && open) {
86+
setOpen(false)
87+
}
88+
}
89+
90+
if (open) {
91+
document.addEventListener("keydown", handleKeyDown)
92+
return () => {
93+
document.removeEventListener("keydown", handleKeyDown)
94+
}
95+
}
96+
}, [open])
97+
8298
const handleOpenChange = (open: boolean) => {
8399
setOpen(open)
84100
// Reset search when closing

0 commit comments

Comments
 (0)