Skip to content

Commit 37288e5

Browse files
committed
refactor(settings): use useHotKey composable for Ctrl+F shortcut
-e Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent c672b9a commit 37288e5

1 file changed

Lines changed: 6 additions & 24 deletions

File tree

apps/settings/src/views/UserManagementNavigation.vue

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@
126126
<script setup lang="ts">
127127
import { mdiAccountOffOutline, mdiAccountOutline, mdiClose, mdiCogOutline, mdiHistory, mdiMagnify, mdiPlus, mdiShieldAccountOutline } from '@mdi/js'
128128
import { translate as t } from '@nextcloud/l10n'
129+
import { useHotKey } from '@nextcloud/vue/composables/useHotKey'
129130
import debounce from 'debounce'
130-
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
131+
import { computed, onBeforeUnmount, ref, watch } from 'vue'
131132
import { useRoute } from 'vue-router/composables'
132133
import NcAppNavigation from '@nextcloud/vue/components/NcAppNavigation'
133134
import NcAppNavigationItem from '@nextcloud/vue/components/NcAppNavigationItem'
@@ -158,29 +159,10 @@ function clearSearch() {
158159
}
159160
onBeforeUnmount(() => commitSearch.clear())
160161
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 })
184166
185167
/** State of the 'new-account' dialog */
186168
const isDialogOpen = ref(false)

0 commit comments

Comments
 (0)