|
1 | 1 | import styles from './Header.module.css';
|
2 | 2 | import { createContext, h } from 'preact';
|
3 |
| -import { useSettings, useTypedTranslation } from '../types.js'; |
| 3 | +import { usePlatformName, useSettings, useTypedTranslation } from '../types.js'; |
4 | 4 | import { signal, useComputed, useSignal, useSignalEffect } from '@preact/signals';
|
5 | 5 | import { useContext } from 'preact/hooks';
|
6 | 6 | import { toRange } from '../history.service.js';
|
@@ -54,6 +54,7 @@ export function SearchProvider({ children, query = { term: '' } }) {
|
54 | 54 | const derivedTerm = useComputed(() => searchState.value.term);
|
55 | 55 | const derivedRange = useComputed(() => searchState.value.range);
|
56 | 56 | const settings = useSettings();
|
| 57 | + const platformName = usePlatformName(); |
57 | 58 | // todo: domain search
|
58 | 59 | // const derivedDomain = useComputed(() => searchState.value.domain);
|
59 | 60 | useSignalEffect(() => {
|
@@ -113,7 +114,24 @@ export function SearchProvider({ children, query = { term: '' } }) {
|
113 | 114 | }
|
114 | 115 | });
|
115 | 116 |
|
| 117 | + const keydown = (e) => { |
| 118 | + const isMacOS = platformName === 'macos'; |
| 119 | + const isFindShortcutMacOS = isMacOS && e.metaKey && e.key === 'f'; |
| 120 | + const isFindShortcutWindows = !isMacOS && e.ctrlKey && e.key === 'f'; |
| 121 | + |
| 122 | + if (isFindShortcutMacOS || isFindShortcutWindows) { |
| 123 | + e.preventDefault(); |
| 124 | + const searchInput = /** @type {HTMLInputElement|null} */ (document.querySelector(`input[type="search"]`)); |
| 125 | + if (searchInput) { |
| 126 | + searchInput.focus(); |
| 127 | + } |
| 128 | + } |
| 129 | + }; |
| 130 | + |
| 131 | + document.addEventListener('keydown', keydown); |
| 132 | + |
116 | 133 | return () => {
|
| 134 | + document.removeEventListener('keydown', keydown); |
117 | 135 | controller.abort();
|
118 | 136 | };
|
119 | 137 | });
|
|
0 commit comments