|
34 | 34 | const onHashChange = () => { currentRoute = window.location.hash || '#/' } |
35 | 35 |
|
36 | 36 | 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') |
40 | 41 |
|
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) { |
43 | 44 | 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 |
45 | 52 | } |
46 | 53 |
|
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) { |
49 | 56 | e.preventDefault() |
50 | 57 | window.location.hash = '#/share' |
| 58 | + return |
51 | 59 | } |
52 | 60 |
|
| 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 | + } |
53 | 70 | } |
54 | 71 |
|
55 | 72 | window.addEventListener('hashchange', onHashChange) |
56 | | - window.addEventListener('keydown', onKeydown) |
| 73 | + window.addEventListener('keydown', onKeydown, { capture: true }) |
57 | 74 | return () => { |
58 | 75 | window.removeEventListener('hashchange', onHashChange) |
59 | | - window.removeEventListener('keydown', onKeydown) |
| 76 | + window.removeEventListener('keydown', onKeydown, true) |
60 | 77 | } |
61 | 78 | }) |
62 | 79 |
|
|
107 | 124 | {/await} |
108 | 125 | {/if} |
109 | 126 | </main> |
| 127 | + |
0 commit comments