opentui(v5b): fix first-letter duplication on always-active refocus

Typing while the textarea was unfocused doubled the FIRST letter: the always-active
handler did ta.focus() AND ta.insertText(key.sequence), but the renderer runs the
global useKeyboard handler BEFORE routing the key to the focused renderable — so
after focus() the same keystroke was also delivered to the now-focused textarea,
inserting it twice. Subsequent keys were fine (textarea already focused → block
skipped). Fix: focus() only; let the textarea insert the char it now receives.
Verified live: typing 'x' then 'y' while blurred yields '❯ xy' (no dup). 85 pass.
This commit is contained in:
alt-glitch 2026-06-09 05:36:37 +00:00
parent 2cd122c9c1
commit 49d90e68c6

View file

@ -146,11 +146,12 @@ export function Composer(props: {
}
}
// 3) always-active input (item 2): a printable key while the textarea lost
// focus reclaims it AND recovers the char (the in-flight event went to this
// global handler, not the unfocused textarea). Nav/scroll keys are untouched.
// focus reclaims it. The renderer runs this GLOBAL handler BEFORE routing the
// key to the focused renderable, so after focus() the SAME keystroke is still
// delivered to the (now-focused) textarea — do NOT insert it here too, or the
// first letter doubles. Nav/scroll keys are untouched.
if (ta && !ta.focused && isPrintableKey(key)) {
ta.focus()
ta.insertText(key.sequence)
}
})