fix(web): focus settings search with command-f (#17859)
This commit is contained in:
1 parent
f0a47b3172
commit
f769e01e28
2 files changed
+18
-30
No files matched your search
@@ -17,7 +17,6 @@ import {
|
||||
type ReactNode,
|
||||
type RefObject,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useReducer,
|
||||
useRef,
|
||||
@@ -1340,28 +1339,6 @@ export function KeybindingsSettingsPanel() {
|
||||
const commandOptions = useMemo(() => buildKeybindingCommandOptions(keybindings), [keybindings]);
|
||||
const whenVariables = useMemo(() => buildWhenVariableOptions(), []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
const isMod = event.metaKey || event.ctrlKey;
|
||||
if (!isMod || event.altKey || event.key.toLowerCase() !== "f") return;
|
||||
|
||||
const target = event.target;
|
||||
if (
|
||||
target !== searchInputRef.current &&
|
||||
target instanceof HTMLElement &&
|
||||
(target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
searchInputRef.current?.focus();
|
||||
searchInputRef.current?.select();
|
||||
};
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
}, []);
|
||||
|
||||
const openKeybindingsFile = useCallback(() => {
|
||||
if (
|
||||
!keybindingsConfigPath ||
|
||||
|
||||
@@ -140,17 +140,28 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key !== "/" || event.metaKey || event.ctrlKey || event.altKey) return;
|
||||
if (event.defaultPrevented || event.isComposing) return;
|
||||
const isFindShortcut =
|
||||
event.key.toLowerCase() === "f" &&
|
||||
(event.metaKey || event.ctrlKey) &&
|
||||
!event.altKey &&
|
||||
!event.shiftKey;
|
||||
const isSlashShortcut =
|
||||
event.key === "/" && !event.metaKey && !event.ctrlKey && !event.altKey;
|
||||
if (!isFindShortcut && !isSlashShortcut) return;
|
||||
|
||||
const target = event.target;
|
||||
if (
|
||||
target instanceof HTMLElement &&
|
||||
(target.tagName === "INPUT" ||
|
||||
target.tagName === "TEXTAREA" ||
|
||||
target.isContentEditable ||
|
||||
// Keep focus inside open dialogs and popups instead of escaping
|
||||
// their focus trap into the sidebar search.
|
||||
target.closest('[role="dialog"], [aria-modal="true"], [data-slot$="popup"]') !== null)
|
||||
((isSlashShortcut &&
|
||||
(target.tagName === "INPUT" ||
|
||||
target.tagName === "TEXTAREA" ||
|
||||
target.isContentEditable)) ||
|
||||
// Preserve dialog and popup focus traps, and let shortcut recorders
|
||||
// capture the keypress without moving focus into the sidebar search.
|
||||
target.closest(
|
||||
'[role="dialog"], [aria-modal="true"], [data-slot$="popup"], [data-keybinding-capture]',
|
||||
) !== null)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user