Skip to content

Commit 4a8bc96

Browse files
committed
fix(shortcuts-linux): hacer globales Ctrl+F/Ctrl+N con captura temprana y enfoque de busqueda cross-route
1 parent f5d9f5c commit 4a8bc96

2 files changed

Lines changed: 44 additions & 15 deletions

File tree

src/App.svelte

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,46 @@
3434
const onHashChange = () => { currentRoute = window.location.hash || '#/' }
3535
3636
function onKeydown(e: KeyboardEvent) {
37-
const tag = (e.target as HTMLElement).tagName
38-
const edit = (e.target as HTMLElement).isContentEditable
39-
if (tag === 'INPUT' || tag === 'TEXTAREA' || edit) return
37+
const key = (e.key || '').toLowerCase()
38+
const hasPrimaryModifier = e.ctrlKey || e.metaKey
39+
const isCtrlF = hasPrimaryModifier && !e.shiftKey && !e.altKey && (key === 'f' || e.code === 'KeyF')
40+
const isCtrlN = hasPrimaryModifier && !e.shiftKey && !e.altKey && (key === 'n' || e.code === 'KeyN')
4041
41-
// Esc → volver atrás
42-
if (e.key === 'Escape' && currentRoute !== '#/' && currentRoute !== '') {
42+
// Global: Ctrl/Cmd+F -> busqueda interna de la app
43+
if (isCtrlF) {
4344
e.preventDefault()
44-
history.back()
45+
if (currentRoute !== '#/' && currentRoute !== '') {
46+
window.location.hash = '#/'
47+
}
48+
setTimeout(() => {
49+
window.dispatchEvent(new CustomEvent('threadsvault:focus-search'))
50+
}, 0)
51+
return
4552
}
4653
47-
// Ctrl/Cmd + N → añadir post
48-
if (e.key === 'n' && (e.ctrlKey || e.metaKey)) {
54+
// Global: Ctrl/Cmd+N -> nuevo post
55+
if (isCtrlN) {
4956
e.preventDefault()
5057
window.location.hash = '#/share'
58+
return
5159
}
5260
61+
const tag = (e.target as HTMLElement).tagName
62+
const edit = (e.target as HTMLElement).isContentEditable
63+
if (tag === 'INPUT' || tag === 'TEXTAREA' || edit) return
64+
65+
// Esc -> volver atras
66+
if (e.key === 'Escape' && currentRoute !== '#/' && currentRoute !== '') {
67+
e.preventDefault()
68+
history.back()
69+
}
5370
}
5471
5572
window.addEventListener('hashchange', onHashChange)
56-
window.addEventListener('keydown', onKeydown)
73+
window.addEventListener('keydown', onKeydown, { capture: true })
5774
return () => {
5875
window.removeEventListener('hashchange', onHashChange)
59-
window.removeEventListener('keydown', onKeydown)
76+
window.removeEventListener('keydown', onKeydown, true)
6077
}
6178
})
6279
@@ -107,3 +124,4 @@
107124
{/await}
108125
{/if}
109126
</main>
127+

src/routes/VaultScreen.svelte

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,24 +213,34 @@
213213
214214
let searchInput: HTMLInputElement
215215
216+
function focusSearch() {
217+
searchInput?.focus()
218+
searchInput?.select()
219+
}
220+
216221
onMount(() => {
217222
void loadVault()
218223
void refreshStalePostMedia()
219224
225+
const onFocusSearch = () => focusSearch()
226+
220227
function onKeydown(e: KeyboardEvent) {
221228
const tag = (e.target as HTMLElement).tagName
222229
if (tag === 'INPUT' || tag === 'TEXTAREA') return
223230
224-
// / o Ctrl+F → focus buscador
225-
if (e.key === '/' || (e.key === 'f' && (e.ctrlKey || e.metaKey))) {
231+
// / -> focus buscador
232+
if (e.key === '/') {
226233
e.preventDefault()
227-
searchInput?.focus()
228-
searchInput?.select()
234+
focusSearch()
229235
}
230236
}
231237
238+
window.addEventListener('threadsvault:focus-search', onFocusSearch)
232239
window.addEventListener('keydown', onKeydown)
233-
return () => window.removeEventListener('keydown', onKeydown)
240+
return () => {
241+
window.removeEventListener('threadsvault:focus-search', onFocusSearch)
242+
window.removeEventListener('keydown', onKeydown)
243+
}
234244
})
235245
</script>
236246

@@ -581,3 +591,4 @@
581591
</div>
582592
{/if}
583593
</div>
594+

0 commit comments

Comments
 (0)