Repository navigation
Conversation
## Description Chromium can split a multiline `insertText` commit into multiple DOM edits when the caret is inside an existing text node. Lexical can then retain only the first line. Route cancelable, non-composing multiline text commits through the existing controlled insertion command before Chromium changes the DOM. Single-line input and the existing newline-only branches are unchanged. Reproduce on Android Chrome with Fcitx5-android: open the [plain-text Lexical Playground](https://playground.lexical.dev/?isRichText=false&emptyEditor=true), type `X`, and insert an `AAA`/`BBB` two-line entry from the keyboard's clipboard panel. Only `XAAA` remains; a native `contenteditable` with the same prefix retains both lines. ## Test plan Chromium: `vitest run --project browser LexicalMultilineInput.test.ts LexicalComposition.test.ts` (system Chromium via local launch configuration). ### Before ```text × handles a multiline text commit in plain text × handles a multiline text commit in rich text AssertionError: expected false to be true // Object.is equality Tests 2 failed (2) ``` ### After ```text ✓ LexicalMultilineInput.test.ts (2 tests) ✓ LexicalComposition.test.ts (24 tests | 1 skipped) Tests 25 passed | 1 skipped (26) ``` Firefox and WebKit were not run locally. An equivalent downstream workaround was verified with the original Fcitx5-android reproduction; the core change is covered by the Chromium regression above.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @wrvsrx! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
AI review status for this pull request.
|
There was a problem hiding this comment.
Thanks for the fix, this looks good. Sending only cancelable, non-composing multiline insertText commits through CONTROLLED_TEXT_INSERTION_COMMAND reuses the path Lexical already takes for the same commit in an empty paragraph, and single-line typing, '\n', '\n\n' and composition commits keep their existing branches. Everything below is optional and non-blocking.
- Let the test reach the native path (
packages/lexical/src/__tests__/browser/LexicalMultilineInput.test.ts:39-52). A syntheticbeforeinputhas no default action, so onmainthe test fails because nothing inserts the text, not because Chromium splits the commit, anddefaultPreventedpins the new routing rather than the bug. AGENTS.md's Testing Strategy puts behavior that depends on the real editing engine in browser or e2e tests: Playwright'skeyboard.insertTextsends a trusted, non-composing text commit that emulates IME input (the playground e2e specs already use it, for exampleMarkdown.spec.mjs), and a browser-test command next totypeTextinscripts/vitest/browserCommands.tscould wrap it. - Assert structure and caret, not only text content.
getTextContent()reads the same for a newline inside oneTextNode, aLineBreakNodeor a paragraph split. Asserting the paragraph's children and the selection (anchor at offset 8 of the text node) would pin the intended result. - Newline shape. The commit lands as one
TextNodecontaining\n, while a plain-text paste of the same text producesLineBreakNodes (insertRawText). That matches what the controlled path already writes in an empty paragraph, so it is fine as is; flagging it in case maintainers prefer the paste shape. - Caret heuristic. The branch shares the trailing
$maybeMoveSelectionPastTrailingAcceptanceBoundary(data)call (LexicalEvents.ts:1513), which reads the key of the last keydown. When no keydown precedes the commit (as withkeyboard.insertText) and the last key was Enter, a commit that ends a text node moves the caret to the next line or block. Skipping that call for this branch, or asserting the caret, would avoid the surprise. - Changeset wording (
.changeset/preserve-multiline-ime-commits.md:5). The new branch is not Android-specific, and.changeset/README.mdasks for a summary of the change from the user's side, for example[fix] Insert the whole text of a multiline input commit, such as an Android keyboard's clipboard entry, inside existing text.
| const event = new InputEvent('beforeinput', { | ||
| bubbles: true, | ||
| cancelable: true, | ||
| data, | ||
| inputType: 'insertText', | ||
| }); | ||
| root.dispatchEvent(event); | ||
|
|
||
| // Allowing the default would let Chromium split this commit into multiple | ||
| // DOM edits, including edits outside the current text node. | ||
| expect(event.defaultPrevented).toBe(true); | ||
| expect(editor.read('force-commit', () => $getRoot().getTextContent())).toBe( | ||
| `X${data}Y`, | ||
| ); |
There was a problem hiding this comment.
Optional, non-blocking: a synthetic beforeinput has no default action, so on main this fails because nothing inserts the text, not because Chromium splits the commit, and defaultPrevented pins the new routing rather than the bug. Playwright's keyboard.insertText sends a trusted, non-composing text commit that emulates IME input (the playground e2e specs already use it); a browser-test command next to typeText in scripts/vitest/browserCommands.ts could wrap it, per AGENTS.md's guidance to test real-engine behavior in browser tests. Asserting the paragraph's children and the caret (anchor at offset 8) would also pin the result more tightly than getTextContent(), which reads the same for a \n inside one TextNode, a LineBreakNode or a paragraph split.
| 'lexical': patch | ||
| --- | ||
|
|
||
| [fix] Preserve multiline text committed by an Android input method into existing text. |
There was a problem hiding this comment.
Nit, optional: the new branch is not Android-specific (any cancelable, non-composing multiline insertText takes it), and .changeset/README.md asks for a summary from the user's side. For example: [fix] Insert the whole text of a multiline input commit, such as an Android keyboard's clipboard entry, inside existing text.
Description
Chromium can split a multiline
insertTextcommit into multiple DOM edits when the caret is inside an existing text node. Lexical can then retain only the first line. Route cancelable, non-composing multiline text commits through the existing controlled insertion command before Chromium changes the DOM. Single-line input and the existing newline-only branches are unchanged.Reproduce on Android Chrome with Fcitx5-android: open the plain-text Lexical Playground, type
X, and insert anAAA/BBBtwo-line entry from the keyboard's clipboard panel. OnlyXAAAremains; a nativecontenteditablewith the same prefix retains both lines.Test plan
Chromium:
vitest run --project browser LexicalMultilineInput.test.ts LexicalComposition.test.ts(system Chromium via local launch configuration).Before
After
Firefox and WebKit were not run locally. An equivalent downstream workaround was verified with the original Fcitx5-android reproduction; the core change is covered by the Chromium regression above.