keep caret from jumping to start when typing fast#1732
Open
iyernaveenr wants to merge 1 commit into
Open
Conversation
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>
Contributor
|
Looks good to me. Thanks for your contribution! @4pmtong, could you please provide a second review? |
Douglasymlai
approved these changes
Jul 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Typing quickly in the chat input makes the cursor jump to the start, so characters land at the beginning.
Root cause
RichChatInputre-tokenizes and reassigns the contentEditable'sinnerHTMLon every keystroke, then restores the caret inside arequestAnimationFramecallback. ReassigninginnerHTMLcollapses 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.