diff --git a/assets/js/keyboard-shortcuts.js b/assets/js/keyboard-shortcuts.js index f5934c4b0..c4812496b 100644 --- a/assets/js/keyboard-shortcuts.js +++ b/assets/js/keyboard-shortcuts.js @@ -29,6 +29,11 @@ export const keyboardShortcuts = [ key: '/', action: searchKeyAction }, + { + key: 'k', + modifier: 'metaKey', + action: searchKeyAction + }, { key: 'g', description: 'Search HexDocs package', @@ -64,9 +69,19 @@ function addEventListeners () { function handleKeyDown (event) { if (state.shortcutBeingPressed) { return } if (event.target.matches('input, textarea')) { return } - if (event.ctrlKey || event.metaKey || event.altKey) { return } - const matchingShortcut = keyboardShortcuts.find(shortcut => shortcut.key === event.key) + const modifiers = { + ctrlKey: event.ctrlKey, + metaKey: event.metaKey, + altKey: event.altKey + } + + const matchingShortcut = keyboardShortcuts.find(shortcut => { + if (shortcut.modifier && !modifiers[shortcut.modifier]) return false + + return shortcut.key === event.key + }) + if (!matchingShortcut) { return } state.shortcutBeingPressed = matchingShortcut