Skip to content

Commit 4d5306e

Browse files
extociRylaa
authored andcommitted
fix(web): focus settings search with command-f (pingdotgg#17859)
(cherry picked from commit f769e01)
1 parent f51e71c commit 4d5306e

2 files changed

Lines changed: 18 additions & 30 deletions

File tree

‎apps/web/src/components/settings/KeybindingsSettings.tsx‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
type ReactNode,
1818
type RefObject,
1919
useCallback,
20-
useEffect,
2120
useMemo,
2221
useReducer,
2322
useRef,
@@ -1340,28 +1339,6 @@ export function KeybindingsSettingsPanel() {
13401339
const commandOptions = useMemo(() => buildKeybindingCommandOptions(keybindings), [keybindings]);
13411340
const whenVariables = useMemo(() => buildWhenVariableOptions(), []);
13421341

1343-
useEffect(() => {
1344-
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
1345-
const isMod = event.metaKey || event.ctrlKey;
1346-
if (!isMod || event.altKey || event.key.toLowerCase() !== "f") return;
1347-
1348-
const target = event.target;
1349-
if (
1350-
target !== searchInputRef.current &&
1351-
target instanceof HTMLElement &&
1352-
(target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable)
1353-
) {
1354-
return;
1355-
}
1356-
1357-
event.preventDefault();
1358-
searchInputRef.current?.focus();
1359-
searchInputRef.current?.select();
1360-
};
1361-
window.addEventListener("keydown", handleKeyDown);
1362-
return () => window.removeEventListener("keydown", handleKeyDown);
1363-
}, []);
1364-
13651342
const openKeybindingsFile = useCallback(() => {
13661343
if (
13671344
!keybindingsConfigPath ||

‎apps/web/src/components/settings/SettingsSidebarNav.tsx‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,28 @@ export function SettingsSidebarNav({ pathname }: { pathname: string }) {
137137

138138
useEffect(() => {
139139
const handleKeyDown = (event: globalThis.KeyboardEvent) => {
140-
if (event.key !== "/" || event.metaKey || event.ctrlKey || event.altKey) return;
140+
if (event.defaultPrevented || event.isComposing) return;
141+
const isFindShortcut =
142+
event.key.toLowerCase() === "f" &&
143+
(event.metaKey || event.ctrlKey) &&
144+
!event.altKey &&
145+
!event.shiftKey;
146+
const isSlashShortcut =
147+
event.key === "/" && !event.metaKey && !event.ctrlKey && !event.altKey;
148+
if (!isFindShortcut && !isSlashShortcut) return;
141149

142150
const target = event.target;
143151
if (
144152
target instanceof HTMLElement &&
145-
(target.tagName === "INPUT" ||
146-
target.tagName === "TEXTAREA" ||
147-
target.isContentEditable ||
148-
// Keep focus inside open dialogs and popups instead of escaping
149-
// their focus trap into the sidebar search.
150-
target.closest('[role="dialog"], [aria-modal="true"], [data-slot$="popup"]') !== null)
153+
((isSlashShortcut &&
154+
(target.tagName === "INPUT" ||
155+
target.tagName === "TEXTAREA" ||
156+
target.isContentEditable)) ||
157+
// Preserve dialog and popup focus traps, and let shortcut recorders
158+
// capture the keypress without moving focus into the sidebar search.
159+
target.closest(
160+
'[role="dialog"], [aria-modal="true"], [data-slot$="popup"], [data-keybinding-capture]',
161+
) !== null)
151162
) {
152163
return;
153164
}

0 commit comments

Comments
 (0)