Skip to content

keep caret from jumping to start when typing fast#1732

Open
iyernaveenr wants to merge 1 commit into
eigent-ai:mainfrom
iyernaveenr:naveen_r_iyer/fix-rich-chat-input-caret-jump
Open

keep caret from jumping to start when typing fast#1732
iyernaveenr wants to merge 1 commit into
eigent-ai:mainfrom
iyernaveenr:naveen_r_iyer/fix-rich-chat-input-caret-jump

Conversation

@iyernaveenr

Copy link
Copy Markdown

Problem

Typing quickly in the chat input makes the cursor jump to the start, so characters land at the beginning.

Root cause

RichChatInput re-tokenizes and reassigns the contentEditable's innerHTML on every keystroke, then restores the caret inside a requestAnimationFrame callback. Reassigning innerHTML collapses the selection to offset 0; deferring the restore to the next frame leaves a window where fast keystrokes are inserted at position 0.

Fix

Restore the caret synchronously immediately after updating the content, and defer only the layout-dependent scrollCaretIntoView. Rich-text/link highlighting and caret preservation are unchanged.

Testing

Type rapidly in the chat input — the caret stays at the insertion point instead of jumping to the start.

RichChatInput reassigned the editable element's innerHTML on
every keystroke and restored the caret in a requestAnimationFrame
callback. Reassigning innerHTML collapses the selection to the start,
so deferring the restore left a frame in which rapid keystrokes were
inserted at the beginning. Restore the caret synchronously right after
updating content; defer only the layout-dependent scroll-into-view.

Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.com>
@Douglasymlai

Copy link
Copy Markdown
Contributor

Looks good to me. Thanks for your contribution! @4pmtong, could you please provide a second review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants