mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
The application shortcut listener read the key alone, so copying with Cmd+C or Ctrl+C toggled the CCTV layer and opened the nearest camera, Cmd+F opened the layers panel and Cmd+1 to 6 changed the visual style. Chords are now left to the browser. Shift is not a chord, a held key still repeats, and Escape dismisses search either way.
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
const STYLE_KEYS = Object.freeze({
|
|
1: 'normal',
|
|
2: 'retro',
|
|
3: 'surveillance',
|
|
4: 'thermal',
|
|
5: 'anime',
|
|
6: 'noir',
|
|
});
|
|
|
|
/**
|
|
* Bind the application's existing bubbling keyboard shortcuts.
|
|
* Capture-phase surfaces keep first refusal. The caller owns each action and
|
|
* persistence; form controls keep native typing except for Escape, and a key
|
|
* held with Cmd, Ctrl or Alt is left to the browser.
|
|
* @param {object} options
|
|
* @param {Document} options.documentRef Keyboard event target.
|
|
* @param {HTMLElement} options.searchInput Additional editing target.
|
|
* @param {object} options.actions Existing application operations.
|
|
* @returns {{destroy: Function}} Synchronous, idempotent listener cleanup.
|
|
*/
|
|
export function bindApplicationShortcuts({
|
|
documentRef,
|
|
searchInput,
|
|
actions,
|
|
}) {
|
|
const onKeyDown = (event) => {
|
|
const isFormControl =
|
|
event.target?.matches?.('select, input, textarea') ||
|
|
event.target === searchInput;
|
|
if (isFormControl && event.key !== 'Escape') return;
|
|
// Cmd+C, Ctrl+F, Cmd+1 and the like belong to the browser and the system.
|
|
// Shift is not a chord here: Shift+C is still C.
|
|
if (
|
|
(event.metaKey || event.ctrlKey || event.altKey) &&
|
|
event.key !== 'Escape'
|
|
)
|
|
return;
|
|
|
|
if (STYLE_KEYS[event.key]) actions.setStyle(STYLE_KEYS[event.key]);
|
|
if (event.key === 'Escape') actions.dismissSearch();
|
|
const key = event.key.toLowerCase();
|
|
if (key === 'h') actions.toggleHud();
|
|
if (key === 'o') actions.toggleOrbit();
|
|
if (key === 'v') actions.toggleCleanView();
|
|
if (key === 'f') actions.toggleLayers();
|
|
if (key === 'd') actions.cycleDetection();
|
|
if (key === 'c') actions.toggleCctv();
|
|
};
|
|
documentRef.addEventListener('keydown', onKeyDown);
|
|
return {
|
|
destroy() {
|
|
documentRef.removeEventListener('keydown', onKeyDown);
|
|
},
|
|
};
|
|
}
|