|
126 | 126 | <script setup lang="ts"> |
127 | 127 | import { mdiAccountOffOutline, mdiAccountOutline, mdiClose, mdiCogOutline, mdiHistory, mdiMagnify, mdiPlus, mdiShieldAccountOutline } from '@mdi/js' |
128 | 128 | import { translate as t } from '@nextcloud/l10n' |
| 129 | +import { useHotKey } from '@nextcloud/vue/composables/useHotKey' |
129 | 130 | import debounce from 'debounce' |
130 | | -import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue' |
| 131 | +import { computed, onBeforeUnmount, ref, watch } from 'vue' |
131 | 132 | import { useRoute } from 'vue-router/composables' |
132 | 133 | import NcAppNavigation from '@nextcloud/vue/components/NcAppNavigation' |
133 | 134 | import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem' |
@@ -158,29 +159,10 @@ function clearSearch() { |
158 | 159 | } |
159 | 160 | onBeforeUnmount(() => commitSearch.clear()) |
160 | 161 |
|
161 | | -/** |
162 | | - * Intercept Ctrl+F (Cmd+F on macOS) so it focuses the local search input |
163 | | - * instead of opening the global unified search. We always stop propagation |
164 | | - * to prevent the global handler from firing; preventDefault is skipped when |
165 | | - * the field already has focus so a second Ctrl+F opens the browser's native |
166 | | - * find-in-page dialog as an escape hatch. |
167 | | - * |
168 | | - * @param event - The keydown event |
169 | | - */ |
170 | | -function onKeyDown(event: KeyboardEvent) { |
171 | | - if (!(event.ctrlKey || event.metaKey) || event.key !== 'f') { |
172 | | - return |
173 | | - } |
174 | | - event.stopImmediatePropagation() |
175 | | - const fieldEl = (searchField.value?.$el as HTMLElement | undefined) ?? null |
176 | | - if (fieldEl?.contains(document.activeElement)) { |
177 | | - return |
178 | | - } |
179 | | - event.preventDefault() |
180 | | - searchField.value?.focus() |
181 | | -} |
182 | | -onMounted(() => window.addEventListener('keydown', onKeyDown, { capture: true })) |
183 | | -onBeforeUnmount(() => window.removeEventListener('keydown', onKeyDown, { capture: true })) |
| 162 | +// Intercept Ctrl/Cmd+F to focus the local search. useHotKey ignores the |
| 163 | +// event when an input/textarea is already focused, so a second press falls |
| 164 | +// through to the browser's native find-in-page. |
| 165 | +useHotKey('f', () => searchField.value?.focus(), { ctrl: true, stop: true, prevent: true }) |
184 | 166 |
|
185 | 167 | /** State of the 'new-account' dialog */ |
186 | 168 | const isDialogOpen = ref(false) |
|
0 commit comments