// 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})); }); })();