{"version":3,"file":"promptFocus.mjs","names":[],"sources":["../../../src/web/lib/promptFocus.ts"],"sourcesContent":["/**\n * Where the keyboard belongs when no overlay holds it.\n *\n * Overlays opened by a shortcut have no trigger element, so the browser has\n * nothing to restore focus to when they close and the caret lands on the\n * body: the next keystroke goes nowhere. The composer registers its input\n * here and every overlay hands focus back to it, which is what makes\n * \"ctrl+k, escape, keep typing\" work. A module-level ref rather than a store\n * because nothing renders from it.\n */\nlet promptInput: HTMLTextAreaElement | null = null;\n\n/** The composer claims the keyboard on mount; the returned disposer releases it. */\nexport function registerPromptInput(element: HTMLTextAreaElement | null): () => void {\n  promptInput = element;\n  return () => {\n    if (promptInput === element) promptInput = null;\n  };\n}\n\n/** Returns the caret to the composer, if there is one and it can take it. */\nexport function focusPrompt(caret?: number): void {\n  if (promptInput === null || promptInput.disabled) return;\n  promptInput.focus();\n  if (caret !== undefined) promptInput.setSelectionRange(caret, caret);\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAI,cAA0C;;AAG9C,SAAgB,oBAAoB,SAAiD;CACnF,cAAc;CACd,aAAa;EACX,IAAI,gBAAgB,SAAS,cAAc;CAC7C;AACF;;AAGA,SAAgB,YAAY,OAAsB;CAChD,IAAI,gBAAgB,QAAQ,YAAY,UAAU;CAClD,YAAY,MAAM;CAClB,IAAI,UAAU,KAAA,GAAW,YAAY,kBAAkB,OAAO,KAAK;AACrE"}