mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-09-03 14:18:02 +00:00
fix(search): don't open the command palette via Cmd/Ctrl+K while typing (#1414)
The global command palette's Cmd/Ctrl+K shortcut fired even when a text field or the code editor held focus, stealing focus mid-edit and, on macOS, clobbering the native Ctrl+K delete-to-end-of-line. Guard the handler with isInputFocused() so the shortcut opens search only when the user is not typing in a field; the toolbar search icon still opens it from anywhere. Add unit tests for the keyboard path.
This commit is contained in:
@@ -18,6 +18,7 @@ import {
|
||||
} from '@/components/ui/command';
|
||||
import { DialogDescription, DialogTitle } from '@/components/ui/dialog';
|
||||
import { useNodes, type Node } from '@/context/NodeContext';
|
||||
import { isInputFocused } from '@/lib/keyboard-guards';
|
||||
import { cn } from '@/lib/utils';
|
||||
import {
|
||||
useCrossNodeStackSearch,
|
||||
@@ -51,6 +52,10 @@ export function GlobalCommandPaletteProvider({ children }: { children: ReactNode
|
||||
// Let cmdk's own Ctrl+K handling take precedence when focus is already inside a palette
|
||||
const target = e.target as HTMLElement | null;
|
||||
if (target?.closest('[cmdk-root]')) return;
|
||||
// Don't hijack Cmd/Ctrl+K while the user is typing in a field or the code
|
||||
// editor: stealing focus mid-edit is surprising, and on macOS Ctrl+K is the
|
||||
// native delete-to-end-of-line. Search still opens elsewhere, or via the icon.
|
||||
if (isInputFocused()) return;
|
||||
e.preventDefault();
|
||||
setOpen(prev => !prev);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user