Skip to content

[lexical] Bug Fix: Do not move anchor when inserting composition start char#8121

Merged
etrepum merged 10 commits intofacebook:mainfrom
kimseongyu:fix-composition-breaks-when-replacing-selection-starting-with-formatted-text
Feb 12, 2026
Merged

[lexical] Bug Fix: Do not move anchor when inserting composition start char#8121
etrepum merged 10 commits intofacebook:mainfrom
kimseongyu:fix-composition-breaks-when-replacing-selection-starting-with-formatted-text

Conversation

@kimseongyu
Copy link
Copy Markdown
Contributor

Description

Current Behavior

Lexical inserts a COMPOSITION_START_CHAR to ensure the browser correctly handles IME composition. However, when this character is inserted, the selection anchor moves forward and first composition stroke is in a selected state. Windows Chrome manages to continue the composition session, But macOS Chrome drops the first stroke and composing is failed.

Changes in This PR

  • Anchor position is continued when the COMPOSITION_START_CHAR is inserted at the beginning of a composition session.
  • After composition, Clean up the COMPOSITION_START_CHAR in the text and reconcile the anchor and focus positions appropriately.

Closes #8119

Test plan

Before

before.mov

After

after.mov

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 7, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Feb 12, 2026 3:30pm
lexical-playground Ready Ready Preview, Comment Feb 12, 2026 3:30pm

Request Review

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 8, 2026

Looks like this is failing e2e tests

@kimseongyu
Copy link
Copy Markdown
Contributor Author

kimseongyu commented Feb 9, 2026

Thank you!

Before I finalize the fix, I have a question regarding a behavior I observed in the E2E test(Can type Hiragana via IME part way through a mention).

In this test case, when the Hiragana character 'す' is entered, a COMPOSITION_SUFFIX (an invisible character) is inserted. I noticed that when I try to move the cursor from 'す' back to the 'e' in "Luke", I have to press the arrow key twice to pass the invisible character.

Is this behavior intentional or unintended side effect? If it is a side effect, I am going to update the E2E test accordingly.

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 9, 2026

It’s only intentional if that’s how IME normally works in native text fields.

@kimseongyu
Copy link
Copy Markdown
Contributor Author

Lexical inserts COMPOSITION_SUFFIX to prevent input errors during composition. However, it is currently only removed from the end of the text, leaving intermediate ones behind. These suffixes cause unexpected behavior. I will update the related e2e tests to ensure all instances are properly cleaned up.

@kimseongyu
Copy link
Copy Markdown
Contributor Author

The test is passed. But there is incorrectly behavior in the firefox when input the composition text. So, I am working on fix it.

Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you call editor.update from inside of another update to the same editor it will run the code out of order, which is very confusing and makes it difficult to debug. I think this should be unnecessary, or should be refactored to make this deferral explicit in some way because this behavior will change at some point in the future (at least generate warnings).

I created #8133 which is this PR plus a commit that makes all of these synchronous, can you check to see if that works as expected for you?

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 11, 2026

At least with Chrome on macOS it looks like the cursor is in the wrong place when doing composition with this PR (compared to the current playground and Apple's TextEdit input behavior) - this PR is on the left

Screen.Recording.2026-02-11.at.10.26.43.mov

@kimseongyu
Copy link
Copy Markdown
Contributor Author

Thanks for the catch! I'm already on it. The bug manifests as a simple position error on macOS, but on Windows, it causes false input position when formatting is applied during composition. I'll include the fix for this in my next push with your previous review.

@etrepum
Copy link
Copy Markdown
Collaborator

etrepum commented Feb 11, 2026

You should be able to cherry-pick this commit which may include changes that I didn't mention in review comments 8d35f04

@kimseongyu
Copy link
Copy Markdown
Contributor Author

@etrepum I resolved all issue in this PR and the tests are all passes!

complete.mov

@kimseongyu kimseongyu requested a review from etrepum February 12, 2026 16:10
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, thank you! The lexical team doesn't currently have any active contributors with much IME expertise so this is very helpful

@etrepum etrepum added this pull request to the merge queue Feb 12, 2026
Merged via the queue into facebook:main with commit 1efd452 Feb 12, 2026
39 checks passed
@kimseongyu kimseongyu deleted the fix-composition-breaks-when-replacing-selection-starting-with-formatted-text branch February 12, 2026 16:38
@etrepum etrepum mentioned this pull request Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: composition breaks when replacing selection starting with formatted text

2 participants