Add slash key to access search.
This commit is contained in:
@@ -170,11 +170,26 @@ 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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user