Fix cursor jumping to beginning in ContentEditable inputs#14
Merged
Fix cursor jumping to beginning in ContentEditable inputs#14
Conversation
Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix cursor movement issue when typing in comments
Fix cursor jumping to beginning in ContentEditable inputs
Nov 10, 2025
Owner
|
@copilot make this more dry |
Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Contributor
Author
Owner
|
@copilot are both files being used? |
Contributor
Author
Yes, both files are being used:
The |
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.
Fix cursor jumping to beginning of input in ContentEditable component
Problem
When typing in a line or comment, the cursor would jump to the beginning of the input after each keystroke, making it impossible to type normally.
Root Cause
onChangewhich updates FirebaseshouldComponentUpdatereturnstrue, causing React to re-renderSolution
Modified the
ContentEditablecomponent with two complementary fixes:Primary Fix: Prevent Re-renders During Typing
Updated
shouldComponentUpdateto returnfalsewhen the element is currently focused (user is actively typing). This prevents unnecessary re-renders and naturally preserves cursor position.Backup Fix: Cursor Position Restore
Extracted cursor positioning logic into a reusable
placeCaretAtPositionhelper function that saves and restores cursor position for edge cases where updates occur when the element doesn't have focus.Implementation Status
ContentEditablecomponentshouldComponentUpdateto prevent re-renders when element is focusedFiles Changed
script.jsx- ModifiedContentEditablecomponent and addedplaceCaretAtPositionhelperscript.js- Compiled JavaScript from JSXSecurity
✅ CodeQL analysis passed with 0 alerts - no security vulnerabilities introduced.
Code Quality
Refactored to follow DRY principles by extracting cursor positioning logic into a reusable helper function, reducing code duplication and improving maintainability.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.