Add slash key to access search.

This commit is contained in:
2026-05-20 04:11:52 +00:00
parent 98fbdc63f1
commit 7aeec90e4f
+18 -3
View File
@@ -170,12 +170,27 @@ function handleEscape() {
searchInputRef.value?.blur(); searchInputRef.value?.blur();
} }
function handleKeydown(e: KeyboardEvent) { function focusSearchInput() {
if ((e.ctrlKey || e.metaKey) && e.key === 'f') {
e.preventDefault();
searchInputRef.value?.focus(); searchInputRef.value?.focus();
searchInputRef.value?.select(); searchInputRef.value?.select();
} }
function handleKeydown(e: KeyboardEvent) {
const target = e.target as HTMLElement | null;
const isTypingTarget = Boolean(
target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable)
);
const isSearchShortcut = (e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'f';
const isSlashShortcut = !e.ctrlKey && !e.metaKey && !e.altKey && e.code === 'Slash';
if (isTypingTarget && !isSearchShortcut) {
return;
}
if (isSearchShortcut || isSlashShortcut) {
e.preventDefault();
focusSearchInput();
}
} }
onMounted(() => { onMounted(() => {