mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-19 01:51:21 +08:00
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:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user