|
1 |
| -import { qs } from './helpers' |
| 1 | +import { isMacOS, qs } from './helpers' |
2 | 2 | import { toggleSidebar } from './sidebar/sidebar-drawer'
|
3 | 3 | import { focusSearchInput } from './search-bar'
|
4 | 4 | import { cycleTheme } from './theme'
|
@@ -29,6 +29,11 @@ export const keyboardShortcuts = [
|
29 | 29 | key: '/',
|
30 | 30 | action: searchKeyAction
|
31 | 31 | },
|
| 32 | + { |
| 33 | + key: 'k', |
| 34 | + hasModifier: true, |
| 35 | + action: searchKeyAction |
| 36 | + }, |
32 | 37 | {
|
33 | 38 | key: 'g',
|
34 | 39 | description: 'Search HexDocs package',
|
@@ -64,9 +69,20 @@ function addEventListeners () {
|
64 | 69 | function handleKeyDown (event) {
|
65 | 70 | if (state.shortcutBeingPressed) { return }
|
66 | 71 | if (event.target.matches('input, textarea')) { return }
|
67 |
| - if (event.ctrlKey || event.metaKey || event.altKey) { return } |
68 | 72 |
|
69 |
| - const matchingShortcut = keyboardShortcuts.find(shortcut => shortcut.key === event.key) |
| 73 | + const matchingShortcut = keyboardShortcuts.find(shortcut => { |
| 74 | + if (shortcut.hasModifier) { |
| 75 | + if (isMacOS() && event.metaKey) { return shortcut.key === event.key } |
| 76 | + if (event.ctrlKey) { return shortcut.key === event.key } |
| 77 | + |
| 78 | + return false |
| 79 | + } else { |
| 80 | + if (event.ctrlKey || event.metaKey || event.altKey) { return false } |
| 81 | + |
| 82 | + return shortcut.key === event.key |
| 83 | + } |
| 84 | + }) |
| 85 | + |
70 | 86 | if (!matchingShortcut) { return }
|
71 | 87 | state.shortcutBeingPressed = matchingShortcut
|
72 | 88 |
|
|
0 commit comments