From 35008ef4b5b68fbae2c27b73b5bc36cba6b786db Mon Sep 17 00:00:00 2001 From: "kiloconnect[bot]" <240665456+kiloconnect[bot]@users.noreply.github.com> Date: Fri, 20 Feb 2026 18:17:26 +0000 Subject: [PATCH] fix(vscode): recalculate textarea layout after paste to fix caret position After pasting a large body of text into the chat input, the textarea height wasn't being recalculated in time, causing the caret position to visually desync from its actual position. Add a handlePaste wrapper that defers adjustHeight() and syncHighlightScroll() via requestAnimationFrame, ensuring the browser has completed the reflow before recalculating dimensions. --- .../webview-ui/src/components/chat/PromptInput.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx b/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx index ed4162e3b..fec184728 100644 --- a/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx +++ b/packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx @@ -152,6 +152,17 @@ export const PromptInput: Component = () => { textareaRef.style.height = `${Math.min(textareaRef.scrollHeight, 200)}px` } + const handlePaste = (e: ClipboardEvent) => { + imageAttach.handlePaste(e) + // After pasting text, the textarea content changes but the layout may not + // have reflowed yet, causing the caret position to be visually out of sync. + // Defer height recalculation to after the browser completes the reflow. + requestAnimationFrame(() => { + adjustHeight() + syncHighlightScroll() + }) + } + const handleInput = (e: InputEvent) => { const target = e.target as HTMLTextAreaElement const val = target.value @@ -304,7 +315,7 @@ export const PromptInput: Component = () => { value={text()} onInput={handleInput} onKeyDown={handleKeyDown} - onPaste={imageAttach.handlePaste} + onPaste={handlePaste} onScroll={syncHighlightScroll} disabled={isDisabled()} rows={1}