From 49d90e68c6570b5f15a2db8a7d066358d324ab8a Mon Sep 17 00:00:00 2001 From: alt-glitch Date: Tue, 9 Jun 2026 05:36:37 +0000 Subject: [PATCH] opentui(v5b): fix first-letter duplication on always-active refocus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- ui-tui-opentui-v2/src/view/composer.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ui-tui-opentui-v2/src/view/composer.tsx b/ui-tui-opentui-v2/src/view/composer.tsx index 4d1c5da7d3f..275f04c18d3 100644 --- a/ui-tui-opentui-v2/src/view/composer.tsx +++ b/ui-tui-opentui-v2/src/view/composer.tsx @@ -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) } })