Repository navigation
[lexical] Bug Fix: Handle iOS 10-key Korean IME deleteContentBackward with targetRange - #8475
Conversation
|
Hi @kotom320! 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! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
It would be great if this also added some kind of test to confirm that the behavior is more correct. Note that we can't do anything with this until the CLA is signed (there is some delay for the bot to confirm it)
|
Test suggestion from a Korean user — the case worth nailing is the text-node boundary, when the IME range straddles two text nodes mid-composition. That's where IME bugs tend to hide in this area. |
|
If the CLA isn't signed we will have to close this eventually but I would be happy to review another attempt at this fix by a contributor who can sign the CLA especially if it includes tests. |
aa2a35b to
cd27fc3
Compare
|
@etrepum |
|
@mayrang since it sounds like you are familiar with this Korean IME do you have any opinions on this solution and how it behaves in the playground? https://lexical-playground-git-fork-kotom320-fix-io-590d2a-fbopensource.vercel.app/ It's tricky for me to validate that it behaves as expected as I have no fluency in Korean |
etrepum
left a comment
There was a problem hiding this comment.
The code looks reasonable to me, the behavior certainly seems like an improvement over the current playground, but I am unsure if it exactly matches the expectations of someone familiar with this language and IME. Will hold off on merging for a bit for a second opinion but approving in the meantime.
|
@etrepum — checked on iOS Safari with the built-in 10키 (천지인) Korean keyboard.
Third-party Korean keyboard apps (Naver SmartBoard, etc.) don't go through this code path — they use a different IME route — so they're unaffected either way. The fix is targeting the iOS built-in 10키 case, which is the only option for users who don't install a third-party keyboard. Side note: iOS 10-key diverges from Android 10-key and from other Korean IMEs at both the browser event layer (no |
|
@mayrang thank you, I will merge this as-is as it's a clear improvement! Please feel free assist or offer PRs on any other IME issue since you have a lot more domain knowledge than most of the active maintainers |
|
Thanks @etrepum. Will keep an eye on the IME-tagged issues and chime in when there's something concrete to add. |
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts FAIL IosKeyboardSuggestions.test.ts > cursor at start of text does not delete (nothing to delete) AssertionError: expected false to be true // Object.is equality 228| expect(handled).toBe(true); FAIL IosKeyboardSuggestions.test.ts > iOS Backspace at the start of the first block > an empty first-block quote collapses to a paragraph AssertionError: expected false to be true // Object.is equality 301| expect(editor.dispatchCommand(KEY_BACKSPACE_COMMAND, event)).toBe(true); FAIL IosKeyboardSuggestions.test.ts > iOS Backspace at the start of the first block > a non-empty first-block quote collapses and keeps its text AssertionError: expected false to be true // Object.is equality 316| expect(editor.dispatchCommand(KEY_BACKSPACE_COMMAND, event)).toBe(true); Test Files 1 failed (1) Tests 3 failed | 10 passed (13) ``` ### After ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit -- packages/lexical-rich-text packages/lexical-plain-text \ packages/lexical-utils packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 104 passed (104) Tests 1780 passed (1780) $ pnpm run lint && pnpm run flow && pnpm run tsc && pnpm run prettier (eslint: no violations) No errors! (tsc: no errors) All matched files use Prettier code style! $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ -- packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done webkit Tests 4 passed (4) chromium Tests 4 passed (4) firefox Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser -- packages/lexical-rich-text Test Files 21 passed (21) Tests 173 passed (173) ``` The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts × cursor at start of text does not delete (nothing to delete) × an empty first-block quote collapses to a paragraph × a non-empty first-block quote collapses and keeps its text × a blank first paragraph before another block is removed AssertionError: expected false to be true // Object.is equality (x4) Test Files 1 failed (1) Tests 4 failed | 11 passed (15) ``` ### After ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit -- packages/lexical-rich-text packages/lexical-plain-text \ packages/lexical-utils packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 104 passed (104) Tests 1780 passed (1780) $ pnpm run lint && pnpm run flow && pnpm run tsc && pnpm run prettier (eslint: no violations) No errors! (tsc: no errors) All matched files use Prettier code style! $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ -- packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done webkit Tests 4 passed (4) chromium Tests 4 passed (4) firefox Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser -- packages/lexical-rich-text Test Files 21 passed (21) Tests 173 passed (173) ``` The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts × cursor at start of text does not delete (nothing to delete) × an empty first-block quote collapses to a paragraph × a non-empty first-block quote collapses and keeps its text × a blank first paragraph before another block is removed AssertionError: expected false to be true // Object.is equality (x4) Test Files 1 failed (1) Tests 4 failed | 11 passed (15) ``` ### After ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit -- packages/lexical-rich-text packages/lexical-plain-text \ packages/lexical-utils packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 104 passed (104) Tests 1780 passed (1780) $ pnpm run lint && pnpm run flow && pnpm run tsc && pnpm run prettier (eslint: no violations) No errors! (tsc: no errors) All matched files use Prettier code style! $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ -- packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done webkit Tests 4 passed (4) chromium Tests 4 passed (4) firefox Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser -- packages/lexical-rich-text Test Files 21 passed (21) Tests 173 passed (173) ``` The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…Backspace at the start of the first block ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its autocomplete/suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). That delegation has one hole: WebKit fires no `beforeinput` when the caret sits at the very start of the editable region. Measured on Safari 26.5, Backspace there produces a `keydown` and nothing else, so nothing performs the deletion, `RangeSelection.deleteCharacter` never runs, and `$collapseAtStart` is never reached. The keystroke is dropped entirely, so a first-block `QuoteNode` or `CodeNode` cannot be turned back into a paragraph, an empty first-block `HeadingNode` cannot either, and a blank first `ParagraphNode` followed by another block is not removed. Chromium does fire `beforeinput` in the same position, so this is iOS-only. Two neighbouring cases are *not* affected, for reasons worth recording: a non-empty first-block heading is deliberately left in place on every platform since meta#8493, and a first-block list is handled by `@lexical/list`'s own `KEY_BACKSPACE_COMMAND` listener at `COMMAND_PRIORITY_BEFORE_EDITOR`, which runs ahead of rich-text's and calls `preventDefault()` itself. `@lexical/plain-text` carries the same pass-through and needs the same carve-out. It registers no nodes of its own, so `ParagraphNode`'s is the only `collapseAtStart` that can run there — a blank first paragraph followed by another block. Enter and paste cannot produce that second block (both insert a line break), but `$initialEditorState`, a restored editor state and direct root mutation all can, and nothing normalizes the root to a single paragraph. Fixing only rich-text would leave one of two identical call sites broken, so the predicate is duplicated there, module-private in each, matching how the neighbouring `$isSelectionCollapsedAtFrontOfIndentedBlock` is kept private to rich-text rather than lifted into `@lexical/utils`. Out of scope, but worth stating so the boundary is not mistaken for an oversight: Backspace at the start of a *later* block still routes through `beforeinput` on iOS, where a separate pre-existing defect mishandles it — the iOS 10-key Korean IME workaround added by meta#8475 applies `removeText()` to any non-collapsed `targetRange`, including the cross-block range WebKit reports at a block boundary, bypassing `deleteCharacter` and with it the block-preserving behavior meta#8493 established. That is a different package and a different fix. This narrows the pass-through with `$isSelectionCollapsedAtStartOfFirstBlock`, so that one caret position takes the same `preventDefault()` + `DELETE_CHARACTER_COMMAND` path every other platform already takes. The predicate is anchored on the root's own first child rather than `getTopLevelElement()`, which stops at shadow roots and slots and would otherwise also match the first block of every table cell, layout item and collapsible section in the document. Whether the caret is at that block's leading edge is delegated to `$isAtStartOfNode` from `@lexical/utils`, which already handles nesting and slot boundaries. Behavior is unchanged everywhere else: the guard is ANDed after `IS_IOS`, the indented-block outdent branch still runs first, and `preventDefault()` on keydown suppresses the `beforeinput` that would otherwise delete a second time. One existing assertion changes as a result — at the start of a first-block paragraph the handler now reports the keystroke as handled, though `ParagraphNode.collapseAtStart` leaves a non-blank paragraph alone, so the content is untouched exactly as before. ## Test plan ### Before ``` $ npx vitest run packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts × cursor at start of text does not delete (nothing to delete) × an empty first-block quote collapses to a paragraph × a non-empty first-block quote collapses and keeps its text × a blank first paragraph before another block is removed AssertionError: expected false to be true // Object.is equality (x4) Test Files 1 failed (1) Tests 4 failed | 11 passed (15) ``` ### After ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts Test Files 1 passed (1) Tests 15 passed (15) $ pnpm run test-unit packages/lexical-rich-text packages/lexical-utils \ packages/lexical-selection packages/lexical/src/__tests__/unit Test Files 101 passed (101) Tests 1766 passed (1766) $ for b in webkit chromium firefox; do VITEST_BROWSER=$b pnpm run test-browser \ packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts; done (identical output from each of the three runs) Test Files 1 passed (1) Tests 4 passed (4) $ VITEST_BROWSER=webkit pnpm run test-browser packages/lexical-rich-text Test Files 2 passed (2) Tests 13 passed (13) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... No errors! $ tsc $ npx prettier --check packages/lexical-rich-text/src/index.ts \ packages/lexical-plain-text/src/index.ts \ packages/lexical/src/__tests__/unit/IosKeyboardSuggestions.test.ts \ packages/lexical-rich-text/src/__tests__/browser/BackspaceBeforeInputAtEditableStart.test.ts Checking formatting... All matched files use Prettier code style! ``` `@lexical/plain-text` has no `__tests__` directory of its own, so its two cases live in `IosKeyboardSuggestions.test.ts` alongside the rich-text ones and are covered by the first two commands. The new tests cover both directions of the guard: an empty and a non-empty first-block quote collapse to a paragraph, an indented first-block quote still outdents instead of collapsing, and a later block, a non-collapsed selection, a later child of the first block, and a shadow-root block mid-document all still pass through to `beforeinput`. Each was checked against a reverted source: with the guard removed three fail, with the predicate anchored on `getTopLevelElement()` the shadow-root case fails, and with the outdent branch removed the indent case fails. The plain-text case fails with only its own guard reverted, so the two halves are covered independently. The engine assumption the carve-out rests on is pinned by a browser-mode characterization test that presses a real Backspace against a plain `contenteditable` with no editor attached — going through Lexical would suppress the `beforeinput` being observed, since its keydown handler calls `preventDefault()` on non-iOS platforms. Headless WebKit reproduces the quirk: no `deleteContentBackward` arrives at the start of a first block, empty or not, while Chromium and Firefox both fire one, and all three fire mid-text and at the start of a later block. Inverting the assumption fails the two WebKit cases and leaves the others green, so the test is a real canary: if WebKit ever starts firing there, it fails and the carve-out can be deleted. Verified on a physical iOS device: a first-block quote and code block now collapse to a paragraph; the suggestion bar still refreshes on Backspace elsewhere; no double deletion at a later block or across a range selection; a shadow-root block mid-document is unaffected; an indented first-block quote outdents; press-and-hold Backspace at the first block start behaves; Korean IME composition is unaffected; a first-block list still collapses via `@lexical/list`'s own higher-priority handler. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). There, the iOS 10-key Korean IME workaround added by meta#8475 applies any non-collapsed `targetRange` with `applyDOMRange()` and deletes it with `removeText()`. That is correct for the IME's jamo deletes, which stay inside one text node, but WebKit reports a non-collapsed range for an ordinary Backspace too. At the start of a block it reports the range from the previous editable position to the caret, skipping any `contenteditable=false` node in between: with `<p>abc</p><div contenteditable="false">…</div><p></p>` and the caret in the empty paragraph, the range is `#text(abc)@3 .. P@0`. `removeText()` deletes everything between the two points and merges the blocks, which skips the rules `RangeSelection.deleteCharacter` applies there: - an empty paragraph after a block decorator should be removed and the decorator selected (meta#7155); on iOS the decorator is deleted too and the caret lands at the end of "abc"; - at the start of a text paragraph after a block decorator only the decorator should be deleted (meta#7155); on iOS the two paragraphs are merged as well; - an empty paragraph before a heading should be removed and the heading kept (meta#8493); on iOS the heading is merged into the paragraph; - an isolated decorator (`isIsolated()`) is never deleted by Backspace (meta#7155), but WebKit reports `#text(ab)@2 .. SPAN@0` across an inline `contenteditable=false` element inside one paragraph, and on iOS it is deleted. This resolves the range on a clone of the selection and takes the fast path only when both ends share the same nearest block element and the range contains no decorator. Anything wider falls through to `DELETE_CHARACTER_COMMAND` from the untouched caret, which is what every other platform runs for Backspace (their keydown handler calls `preventDefault()`, so they never see a `targetRange`). The IME case is unchanged: a jamo delete is a text-only range inside one block, and so is a range straddling two adjacent text nodes in one paragraph. The keydown pass-through is untouched, so the suggestion bar keeps refreshing, and the fallback already calls `event.preventDefault()`, so nothing is deleted twice. Resolving on a clone also means a range that `applyDOMRange()` resolves to a collapsed point no longer moves the caret before the fallback runs. List items are unaffected: `@lexical/list` handles Backspace at their start on keydown, ahead of the iOS pass-through (meta#8829). Out of scope: a text-only range inside one block still takes the `removeText()` fast path, so segmented and token text nodes delete differently there than on other platforms. That predates this change (meta#8475) and needs the fast path itself, which the IME depends on. Backspace at the very start of the first block, where WebKit fires no `beforeinput` at all, is a separate defect fixed on its own in the first-block iOS Backspace change. ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph AssertionError: expected { json: { root: { …(8) } }, …(1) } to deeply equal { json: { root: { …(8) } }, …(1) } (x4) Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts Test Files 1 passed (1) Tests 10 passed (10) $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 345 passed (345) Tests 5740 passed | 1 skipped (5741) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc $ npx prettier --check packages/lexical/src/LexicalEvents.ts \ packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Checking formatting... All matched files use Prettier code style! ``` Each new unit test runs the same document through the iOS `targetRange` path and through `DELETE_CHARACTER_COMMAND` and asserts the results match. The one missing from Before, a plain paragraph boundary, passes before the fix too (merging gives the same result either way) and guards that boundary. The existing IME tests pass unchanged. The browser test pins the engine behavior the unit tests fake with a `StaticRange`: it presses a real Backspace in a plain `contenteditable` with no editor attached, and asserts that WebKit reports a non-collapsed range that contains the `contenteditable=false` block, from both an empty and a text paragraph. It runs on WebKit only. Firefox reports a range that does not contain the block in the empty-paragraph case, and the fix only runs on iOS. Chromium and Firefox skip it, so its signal comes from the macOS + webkit job of the extended matrix. Not yet verified on a physical iOS device. To check there: - Backspace in an empty paragraph after a block decorator removes the paragraph and selects the decorator, and a second Backspace deletes the decorator without the page scrolling to the top (see meta#9113); - Backspace at the start of a text paragraph after a block decorator, and between two plain paragraphs, matches desktop; - Backspace at the start of a heading after an empty paragraph keeps the heading; - 10-key Korean input of "안녕하세요" is correct (meta#8475) and 2-set Korean composition is unaffected; - the suggestion bar still refreshes after Backspace; - press-and-hold Backspace and Backspace over a range selection delete once.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the system keyboard keeps refreshing its suggestion bar, and the deletion is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). There, the iOS 10-key Korean IME workaround added by meta#8475 applies any non-collapsed `targetRange` with `applyDOMRange()` and deletes it with `removeText()`. That is correct for the IME's jamo deletes, which stay inside one text node, but WebKit reports a non-collapsed range for an ordinary Backspace too. At the start of a block it reports the range from the previous editable position to the caret, skipping any `contenteditable=false` node in between: with `<p>abc</p><div contenteditable="false">…</div><p></p>` and the caret in the empty paragraph, the range is `#text(abc)@3 .. P@0`. `removeText()` deletes everything between the two points and merges the blocks, which skips the rules `RangeSelection.deleteCharacter` applies there: - an empty paragraph after a block decorator should be removed and the decorator selected (meta#7155); on iOS the decorator is deleted too and the caret lands at the end of "abc"; - at the start of a text paragraph after a block decorator only the decorator should be deleted (meta#7155); on iOS the two paragraphs are merged as well; - an empty paragraph before a heading should be removed and the heading kept (meta#8493); on iOS the heading is merged into the paragraph; - an isolated decorator (`isIsolated()`) is never deleted by Backspace (meta#7155), but WebKit reports `#text(ab)@2 .. SPAN@0` across an inline `contenteditable=false` element inside one paragraph, and on iOS it is deleted. This resolves the range on a clone of the selection and takes the fast path only when both ends resolve inside the same, non-null nearest block element and the range contains no decorator. Anything wider falls through to `DELETE_CHARACTER_COMMAND` from the untouched caret, which is what every other platform runs for Backspace (their keydown handler calls `preventDefault()`, so they never see a `targetRange`). The IME case is unchanged: a jamo delete is a text-only range inside one block, and so is a range straddling two adjacent text nodes in one paragraph. The keydown pass-through is untouched, so the suggestion bar keeps refreshing, and the fallback already calls `event.preventDefault()`, so nothing is deleted twice. Resolving on a clone also means a range that `applyDOMRange()` resolves to a collapsed point no longer moves the caret before the fallback runs. The same-block test requires a non-null block on each end rather than comparing the two `$findMatchingParent()` results directly. That helper stops before the `RootNode` and returns null, so two points with no block ancestor would compare equal and read as "same block". This part is hardening, not a reachable fix: I could not construct a document where it happens, because `applyDOMRange()` normalizes a root-level DOM offset down into a child block, so both ends resolve to a paragraph or heading element point, or to a text point inside one. Four shapes were probed (two empty paragraphs, an empty paragraph followed by a text paragraph, a single empty paragraph, and an empty paragraph followed by a heading) and none produced a point on the `RootNode`. No test pins the null rejection for that reason; a test that exercises it would pass without it. Both lookups are hoisted into locals, which also drops a duplicated tree walk. List items are unaffected: `@lexical/list` handles Backspace at their start on keydown, ahead of the iOS pass-through (meta#8829). Out of scope: a text-only range inside one block still takes the `removeText()` fast path, so segmented and token text nodes delete differently there than on other platforms. That predates this change (meta#8475) and needs the fast path itself, which the IME depends on. Backspace at the very start of the first block, where WebKit fires no `beforeinput` at all, is a separate defect fixed on its own in the first-block iOS Backspace change. ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph AssertionError: expected { json: { root: { …(8) } }, …(1) } to deeply equal { json: { root: { …(8) } }, …(1) } (x4) Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts Test Files 1 passed (1) Tests 10 passed (10) $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 345 passed (345) Tests 5740 passed | 1 skipped (5741) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc $ npx prettier --check packages/lexical/src/LexicalEvents.ts \ packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Checking formatting... All matched files use Prettier code style! ``` Each new unit test runs the same document through the iOS `targetRange` path and through `DELETE_CHARACTER_COMMAND` and asserts the results match. The one missing from Before, a plain paragraph boundary, passes before the fix too (merging gives the same result either way) and guards that boundary. The existing IME tests pass unchanged. The browser test pins the engine behavior the unit tests fake with a `StaticRange`: it presses a real Backspace in a plain `contenteditable` with no editor attached, and asserts that WebKit reports a non-collapsed range that contains the `contenteditable=false` block, from both an empty and a text paragraph. It runs on WebKit only. Firefox reports a range that does not contain the block in the empty-paragraph case, and the fix only runs on iOS. Chromium and Firefox skip it, so its signal comes from the macOS + webkit job of the extended matrix. The non-null block requirement was added after the runs above and re-verified on its own. The file and test counts differ from the run above because the branch was rebased onto a newer `main` in between: ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ pnpm run tsc $ tsc $ pnpm exec eslint packages/lexical/src/LexicalEvents.ts $ pnpm exec prettier --check packages/lexical/src/LexicalEvents.ts Checking formatting... All matched files use Prettier code style! ``` It rejects strictly more ranges than the version the browser run above exercised, and is behavior-preserving for every document shape that could be constructed, so those results stand. The browser test was not re-run for it, since it characterizes the engine rather than this predicate. Not yet verified on a physical iOS device. To check there: - Backspace in an empty paragraph after a block decorator removes the paragraph and selects the decorator, and a second Backspace deletes the decorator without the page scrolling to the top (see meta#9113); - Backspace at the start of a text paragraph after a block decorator, and between two plain paragraphs, matches desktop; - Backspace at the start of a heading after an empty paragraph keeps the heading; - 10-key Korean input of "안녕하세요" is correct (meta#8475) and 2-set Korean composition is unaffected; - the suggestion bar still refreshes after Backspace; - press-and-hold Backspace and Backspace over a range selection delete once.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. List-item Backspace is also unaffected, since `@lexical/list` handles it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. Backspace at the start of a list item is also unaffected, since `@lexical/list` consumes it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. Backspace at the start of a list item is also unaffected, since `@lexical/list` consumes it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5966 passed | 1 skipped (5967) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
…s that cross a block or a decorator ## Description On iOS, `KEY_BACKSPACE_COMMAND` returns `false` without calling `event.preventDefault()` so the keyboard keeps refreshing its suggestion bar, and Backspace is delegated to the `beforeinput` `deleteContentBackward` handler (meta#5841, meta#8725). The Korean 10-key IME workaround added by meta#8475 handles a non-collapsed `targetRange` with `removeText()`. WebKit also reports non-collapsed ranges for ordinary Backspace. At block or decorator boundaries, deleting those ranges directly can bypass `RangeSelection.deleteCharacter` rules, causing decorators to be deleted or blocks to be merged incorrectly (meta#7155, meta#8493). This change resolves the range on a cloned selection and uses the `removeText()` fast path only when both ends belong to the same block and the range contains no decorator. Other ranges fall through to `DELETE_CHARACTER_COMMAND` from the original caret, matching Backspace behavior on other platforms. The fallback already calls `event.preventDefault()`, so nothing is deleted twice. The same-block check also requires a non-null block, since two failed `$findMatchingParent()` lookups would otherwise compare equal. This is defensive hardening: `applyDOMRange()` normalized all probed root-level offsets into child blocks, so no reachable case was found to test separately. The Korean IME path remains unchanged because its jamo deletion stays within a text-only range inside one block. Backspace at the start of a list item is also unaffected, since `@lexical/list` consumes it on keydown ahead of the iOS pass-through (meta#8829). Out of scope: text-only ranges within one block still use the existing `removeText()` path, so segmented and token text nodes delete differently there than on other platforms (meta#8475). ## Test plan ### Before ``` $ pnpm run test-unit packages/lexical/src/__tests__/unit/LexicalIosKoreanIME.test.ts × keeps the block decorator and selects it when backspacing an empty paragraph after it × matches DELETE_CHARACTER_COMMAND at the start of a text paragraph after a block decorator × keeps an isolated inline decorator that the range skips over × keeps the heading when backspacing at its start after an empty paragraph Test Files 1 failed (1) Tests 4 failed | 6 passed (10) ``` ### After ``` $ pnpm run test-unit packages/lexical packages/lexical-rich-text packages/lexical-plain-text Test Files 360 passed (360) Tests 5986 passed | 1 skipped (5987) $ VITEST_BROWSER=webkit pnpm run test-browser \ packages/lexical/src/__tests__/browser/BackspaceTargetRangeAcrossDecorator.test.ts Test Files 1 passed (1) Tests 2 passed (2) $ pnpm run lint && pnpm run flow && pnpm run tsc $ eslint ./ Running Flow... Found 0 errors $ tsc ``` The new unit tests compare the iOS `targetRange` path with `DELETE_CHARACTER_COMMAND` for the same document. The browser test confirms that a real Backspace can produce a non-collapsed target range spanning a `contenteditable=false` block. It runs on WebKit only and is skipped on Chromium and Firefox, so its signal comes from the macOS + webkit job of the extended matrix. Verified on a physical iOS device (iPhone 15 Pro, iOS 26.6.2). The device verification predates the non-null defensive hardening described above, which has not been re-verified on device.
Description
The iOS 10-key (천지인/Chunjiin) Korean keyboard does not fire
compositionstart/compositionendevents. Instead, each syllable composition step sends:beforeinputdeleteContentBackwardwith a non-collapsedtargetRange— to erase the current in-progress syllablebeforeinputinsertText— to insert the updated syllableBecause
editor.isComposing()is alwaysfalsefor this keyboard type, Lexical falls through toDELETE_CHARACTER_COMMAND, which ignorestargetRangeentirely and deletes one character before the cursor. The wrong character is deleted, and orphaned jamo accumulate in the editor state with each composition step.This PR adds a guard in the
deleteContentBackwardhandler: when on iOS with a non-collapsedtargetRange, callselection.applyDOMRange(targetRange)andremoveText()to delete exactly the range the IME requested, then return early.If
applyDOMRangecannot resolve the range (collapsed result), the code falls through to the existing path unchanged.targetRangeandIS_IOSare already in scope at the call site — no new imports or dependencies needed.Test plan
Before
Typing 안녕하세요 on iOS 10-key (천지인) keyboard produces corrupted output: 안녕하ᄉ세 ᄋᄋ요 (orphaned jamo appear equal to the number of dot presses per vowel)
ScreenRecording_05-07-2026.17-38-05_1.MOV
After
Typing 안녕하세요 on iOS 10-key (천지인) keyboard produces correct output: 안녕하세요