# Global Search Keyboard Shortcut Design
## Business Problem
When exploring large family trees in Topola Genealogy, users frequently need to
locate specific individuals quickly using the search feature. Currently,
accessing the search box requires moving the hand to the mouse or trackpad,
navigating the cursor to the top bar, and clicking the input field, which breaks
the flow of keyboard-driven navigation. This document proposes introducing a
global keyboard shortcut (the `/` key) to instantly focus the search input,
allowing users to search without manual mouse interaction. By streamlining this
transition, the application provides a faster, more accessible, and premium
keyboard-centric workflow for power users navigating complex genealogical data.
---
## Technical Plan
The shortcut mechanism is designed to be lightweight, modular, and resilient
against responsive layout duplication. Rather than introducing complex
third-party shortcut libraries, the feature leverages standard web browser event
handling, custom React hooks, standard accessibility attributes, and a
centralized input registry.
### Major Components and Workflow
1. **The Encapsulated Hook (`useSearchShortcut`):** The keyboard shortcut logic
is encapsulated within a custom hook `useSearchShortcut`
(`src/menu/use_search_shortcut.ts`). Rather than being called by individual
`SearchBar` components, the hook is invoked once at the layout level in
`TopBar` (`src/menu/top_bar.tsx`). Individual `SearchBar` instances register
their underlying `` DOM elements in a centralized module-level
registry (`registeredSearchInputs` `Set`). This ensures a single `window`
`keydown` event listener manages focus across all responsive search bar
instances.
2. **The Modifier Guard:** To prevent conflicts with system-level and
browser-level shortcuts (such as `Cmd + /` for help or extensions, or
`Ctrl + /` for toggling comments), the listener ignores keydown events with
`Cmd/Meta`. It also ignores `Ctrl` or `Alt` unless both are pressed
simultaneously (`Ctrl + Alt`), allowing `AltGr` combinations on
international keyboards to function properly.
3. **The IME Composition & Default Prevented Guard:** To avoid hijacking
keystrokes when international users are typing using an Input Method Editor
(IME) for CJK (Chinese, Japanese, Korean) languages or when another event
handler has already intercepted the keypress, the listener ignores keydown
events when `event.isComposing === true` or
`event.defaultPrevented === true`.
4. **The Smart Filter (Collision, Repeat & Modal Guards):** Before taking
action, the listener verifies `event.key === '/'` and checks three
conditions:
- **Collision Guard (`isTextEditable`):** It extracts the event path
(supporting Shadow DOM encapsulation via `event.composedPath()`) and
traverses all nodes in the path to check for ``, `