import{f as e}from"./vscode-api-DjORcpSo.js";var t=[`[role="dialog"][data-state="open"]`,`[role="menu"][data-state="open"]`,`[role="listbox"][data-state="open"]`].join(`, `),n=`[data-codex-terminal]`,r=[n,`dil-renderer`].join(`, `),i=new Map,a=new Map,o=new Map,s=null;function c(){let e=_();e&&requestAnimationFrame(()=>{e.focus()})}function l(e,{composerId:t,isPrimaryComposer:n}){let r=()=>{s=e};return i.set(e,{composerId:t,isPrimaryComposer:n}),e.addEventListener(`focus`,r),document.activeElement===e&&(s=e),()=>{i.delete(e),e.removeEventListener(`focus`,r),s===e&&(s=null)}}function u(e,t){let n=a.get(e)??new Set;return a.size===0&&window.addEventListener(`keydown`,g,!0),n.add(t),a.set(e,n),()=>{n.delete(t),n.size===0&&a.delete(e),a.size===0&&window.removeEventListener(`keydown`,g,!0)}}function d(t,n,r){let i=o.get(t);if(i==null){let n=new Map;i={handlersByComposerInput:n,unsubscribe:e.subscribe(t,e=>{let t=_();if(t!=null)for(let r of n.get(t)??[])r(e)})},o.set(t,i)}let a=i.handlersByComposerInput.get(n)??new Set;return a.add(r),i.handlersByComposerInput.set(n,a),()=>{a.delete(r),a.size===0&&i.handlersByComposerInput.delete(n),i.handlersByComposerInput.size===0&&(i.unsubscribe(),o.delete(t))}}function f(e){return _()===e}function p(e){let t=_();return t!=null&&i.get(t)?.composerId===e}function m(e=document){(e.querySelector(n)?.querySelector(`textarea`))?.focus()}function h({composerController:e,event:n}){v(n)&&(n.composedPath().some(e=>e instanceof HTMLElement&&(y(e)||e.closest(r)!=null))||document.querySelector(t)!=null||(n.preventDefault(),e.focus(),e.insertTextAtSelection(n.key)))}function g(e){let t=_();if(t!=null)for(let n of a.get(t)??[])n(e)}function _(){if(s!=null&&s.isConnected&&i.has(s))return s;s=null;for(let[e,{isPrimaryComposer:t}]of i)if(t&&e.isConnected)return e;for(let e of i.keys())if(e.isConnected)return e;return document.querySelector(`[data-codex-composer]`)}function v(e){return!e.defaultPrevented&&!e.isComposing&&!e.metaKey&&!e.ctrlKey&&e.key!==` `&&e.key!==`\xA0`&&e.key.length===1}function y(e){if(e==null)return!1;if(e.isContentEditable)return!0;let t=e.tagName.toLowerCase();return t===`input`||t===`textarea`||t===`select`?!0:e.closest(`[contenteditable='true']`)!=null}export{u as a,h as c,f as i,m as n,d as o,p as r,l as s,c as t};
//# sourceMappingURL=focus-composer-D2R3KWg-.js.map