Files
pages/static/js/home-type-search.js
T
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

25 lines
1.5 KiB
JavaScript

// Type-to-search is intentionally limited to the home page. Never capture typing
// in another editor, a modal, an open menu, or an OS/browser keyboard shortcut.
(() => {
const input = document.querySelector('[data-home-type-search]');
if (!input) return;
document.addEventListener('keydown', event => {
if (event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) return;
if (event.target.closest?.('input,textarea,select,button,a,summary,[contenteditable]:not([contenteditable="false"]),[role="textbox"]')) return;
if ([...document.querySelectorAll('dialog[open],details[open],[role="dialog"]:not(dialog),[aria-modal="true"]:not(dialog)')]
.some(surface => !surface.hidden && surface.getClientRects().length)) return;
if (window.getSelection()?.toString()) return;
const composing = event.key === 'Process' || event.keyCode === 229;
if (!composing && ([...event.key].length !== 1 || event.key.trim() === '')) return;
document.dispatchEvent(new Event('home:search'));
if (input.closest('[inert]') || !input.getClientRects().length) return;
input.focus({preventScroll: true});
// Redirect IME's native composition to the input without synthesizing text.
if (composing) return;
event.preventDefault();
// Search inputs do not support setRangeText/selectionStart in all browsers.
input.value += event.key;
input.dispatchEvent(new Event('input', {bubbles: true}));
});
})();