From 9ab28a9b36cf13bf6cb2b40afba054d37bfc9832 Mon Sep 17 00:00:00 2001 From: Alex Shpak Date: Sun, 17 May 2026 23:27:08 +0200 Subject: [PATCH] Allow Cmd/Ctrl+K for search, remove 's' --- assets/search.js | 28 +++++++++++----------------- layouts/_partials/docs/search.html | 2 +- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/assets/search.js b/assets/search.js index 8e1cf5b..9f62a05 100644 --- a/assets/search.js +++ b/assets/search.js @@ -34,13 +34,15 @@ import Fuse from '{{ "fuse.min.mjs" | relURL }}' input.addEventListener('focus', init); input.addEventListener('keyup', search); - document.addEventListener('keypress', focusSearchFieldOnKeyPress); + document.addEventListener('keydown', focusOnKeyDown); /** - * @param {Event} event + * @param {KeyboardEvent} event */ - function focusSearchFieldOnKeyPress(event) { - if (event.target.value !== undefined) { + function focusOnKeyDown(event) { + if (event.key === 'k' && (event.metaKey || event.ctrlKey)) { + event.preventDefault(); + input.focus(); return; } @@ -48,22 +50,14 @@ import Fuse from '{{ "fuse.min.mjs" | relURL }}' return; } - const characterPressed = String.fromCharCode(event.charCode); - if (!isHotkey(characterPressed)) { + if (event.target.value !== undefined) { return; } - input.focus(); - event.preventDefault(); - } - - /** - * @param {String} character - * @returns {Boolean} - */ - function isHotkey(character) { - const dataHotkeys = input.getAttribute('data-hotkeys') || ''; - return dataHotkeys.indexOf(character) >= 0; + if (event.key === '/') { + event.preventDefault(); + input.focus(); + } } function init() { diff --git a/layouts/_partials/docs/search.html b/layouts/_partials/docs/search.html index af64538..0f7a577 100644 --- a/layouts/_partials/docs/search.html +++ b/layouts/_partials/docs/search.html @@ -3,7 +3,7 @@ + maxlength="64" />