fix: prevent cursor jump during IME composition in colored text#7626
Open
semimikoh wants to merge 2 commits intoueberdosis:mainfrom
Open
fix: prevent cursor jump during IME composition in colored text#7626semimikoh wants to merge 2 commits intoueberdosis:mainfrom
semimikoh wants to merge 2 commits intoueberdosis:mainfrom
Conversation
When typing with IME (Korean/Chinese/Japanese) before the last character of colored text, the cursor would jump to the end of the paragraph. Root cause: ProseMirror's DOMSerializer sets styles via style.cssText, which causes Chrome to normalize hex colors (#FF0000) to rgb format (rgb(255, 0, 0)). During IME composition, this mismatch between the stored mark attributes and re-parsed DOM values causes findDiff to detect the entire mark region as changed, triggering a full replacement that misplaces the cursor. Fix: Add a custom markView to TextStyle that uses setAttribute instead of cssText, preserving the original color format. Also filter empty strings in parseHTML and injectExtensionAttributesToParseRule to prevent additional attribute mismatches. Closes ueberdosis#7621
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: de4cbae The changes in this PR will be included in the next version bump. This PR includes changesets to release 72 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
When typing with IME (Korean/Chinese/Japanese) before the last character
of colored text, the cursor would jump to the end of the paragraph.
Root cause: ProseMirror's DOMSerializer sets styles via style.cssText,
which causes Chrome to normalize hex colors (#FF0000) to rgb format
(rgb(255, 0, 0)). During IME composition, this mismatch between the
stored mark attributes and re-parsed DOM values causes findDiff to
detect the entire mark region as changed, triggering a full replacement
that misplaces the cursor.
Fix: Add a custom markView to TextStyle that uses setAttribute instead
of cssText, preserving the original color format. Also filter empty
strings in parseHTML and injectExtensionAttributesToParseRule to prevent
additional attribute mismatches.
Closes #7621
Changes Overview
Fix cursor jumping to end of paragraph when typing with IME (Korean/Chinese/Japanese) before the last character of text styled with
color/textStyle marks.
addMarkViewto TextStyle extension that usessetAttributeinstead ofstyle.cssTextparseHTMLfor color, backgroundColor, fontFamily, fontSize, lineHeightinjectExtensionAttributesToParseRuleImplementation Approach
Root cause: ProseMirror's
DOMSerializersets styles viadom.style.cssText, which causes Chrome to normalize hex colors (#FF0000) torgb (
rgb(255, 0, 0)). During IME composition,MarkViewDescbecomesCONTENT_DIRTYand falls back to re-parsing the DOM — reading thenormalized rgb value instead of the original hex. This mismatch makes
findDiffdetect the entire mark region as changed, triggering afull-range replacement where Chrome's composition guard blocks correct cursor positioning.
Fix: A custom
addMarkViewcreates the span usingspan.setAttribute('style', ...)which preserves the original color format, preventingthe hex→rgb normalization.
Alternatives considered:
inclusive: falseon textStyle mark — causes side effects (new text won't inherit style at mark boundary)Testing Done
Verification Steps
Additional Notes
Debug logging confirmed the issue — during IME composition,
findDiffreturns{start: 410, endA: 429, endB: 429}(endA==endB meansmark-only change), replacing the entire colored range instead of just the inserted text. This only happens in Chrome due to
cssTextnormalization.
Open to feedback if there's a better approach!
Checklist
Related Issues
Closes #7621