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.
This commit is contained in:
kiloconnect[bot]
2026-02-20 18:17:26 +00:00
parent b39006f562
commit 35008ef4b5
@@ -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}