diff --git a/app/app.vue b/app/app.vue index 95a289b1a..6c974fb29 100644 --- a/app/app.vue +++ b/app/app.vue @@ -47,22 +47,36 @@ if (import.meta.server) { setJsonLd(createWebSiteSchema()) } +function focusSearchOrNavigate() { + const searchInput = document.querySelector( + 'input[type="search"], input[name="q"]', + ) + + if (searchInput) { + searchInput.focus() + return + } + + router.push({ name: 'search' }) +} + onKeyDown( '/', e => { if (isEditableElement(e.target)) return e.preventDefault() + focusSearchOrNavigate() + }, + { dedupe: true }, +) - const searchInput = document.querySelector( - 'input[type="search"], input[name="q"]', - ) - - if (searchInput) { - searchInput.focus() - return - } - - router.push({ name: 'search' }) +onKeyDown( + // Explicitly check Ctrl+K for broader compatibility (especially Firefox) + e => e.ctrlKey && e.key === 'k', + e => { + if (isEditableElement(e.target)) return + e.preventDefault() + focusSearchOrNavigate() }, { dedupe: true }, ) diff --git a/app/components/AppFooter.vue b/app/components/AppFooter.vue index b7e745377..8daf2c378 100644 --- a/app/components/AppFooter.vue +++ b/app/components/AppFooter.vue @@ -48,6 +48,10 @@ const showModal = () => modalRef.value?.showModal?.() / {{ $t('shortcuts.focus_search') }} +
  • + Ctrl+K + {{ $t('shortcuts.focus_search') }} +
  • ? {{ $t('shortcuts.show_kbd_hints') }}