Repository navigation
[lexical-list] Bug Fix: Backspace at start of list item outdents or converts to paragraph - #8829
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Is the |
cf14c2c to
6d025d4
Compare
|
Not entirely — I moved the conversion/outdent/removal logic into |
|
Claude seems to think that there's some missing pieces here that could be satisfied with Reviewed at 6d025d4. The refactor direction is right — consolidating the policy into The
|
|
Pushed 6bb51bd. Dropped the I kept it on if (isBackspace(event)) {
dispatchCommand(editor, KEY_BACKSPACE_COMMAND, event);
} else {
dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true);
}The Tested in Chrome, Firefox, Safari. |
…onverts to paragraph Closes meta#6334
…AtStart Consolidates $handleListBackspaceAtStart into ListItemNode.collapseAtStart so that KEY_BACKSPACE_COMMAND and DELETE_CHARACTER_COMMAND produce identical behavior. The KEY_BACKSPACE_COMMAND handler now only handles the decorator-adjacent case (meta#5072).
Extract list items into named variables so .select() calls resolve against ListItemNode instead of LexicalNode.
- Remove previousSibling gate: all list items at offset 0 now route through collapseAtStart, not just non-first items - isNestedListNode returns false instead of true to defer to default deleteCharacter behavior (outdent via $collapseAtStart walker) - Empty items convert to paragraphs instead of merging into previous sibling, matching Google Docs / Notion behavior - Use paragraph.selectStart() for reliable cursor positioning - Respect collapseAtStart return value in KEY_BACKSPACE_COMMAND handler - Add list-type-preservation test for split
…AtStart change Empty non-first list items now convert to paragraphs instead of merging into the previous item, so deleting through them requires one extra Backspace press.
e94aa2c to
a63ca63
Compare
… merge ## Description The merge of meta#8829 introduced a new `isNestedListNode` call in `ListItemNode.collapseAtStart`; update it to the renamed `$isNestedListNode`. ## Test plan ### After `pnpm run tsc` passes and all 119 lexical-list unit tests pass. No references to the old name remain. Co-Authored-By: Claude Fable 5 <[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.
…s in CHANGELOG.md by the call shapes they break, and add the missing v0.48 list Backspace behavior change ## Description Three backfilled CHANGELOG.md entries did not tell people upgrading who is affected or what to change: - v0.46.0, #8661: the breaking entry said traversal methods "return the base node type" and only named annotated assignments. It did not say that the methods (and `$getNodeByKey` / `$getNodeByKeyOrThrow`) gained a non-generic first overload, so a call without a type argument that used to infer `T` from where its result went (a function argument, a return value, an annotated variable or array) now returns `LexicalNode` and stops compiling. Detect now names those call shapes and the TypeScript error, Migration shows the function-argument case, and the matching deprecation entry now has its own Detect and says the overloads were removed from TypeScript in v0.53.0 (#9479), while the Flow declarations keep them after #9529, instead of "Removal: not scheduled". - v0.49.0, #8877: the entry said `LexicalCommand<T>` is invariant, but Detect only named `LexicalCommand<unknown>` and explicit generics. A `registerCommand` listener whose parameter annotation is narrower or wider than the payload (for example `(event: KeyboardEvent) => ...` for `KEY_ENTER_COMMAND`, whose payload is `KeyboardEvent | null`), or a helper typed `LexicalCommand<KeyboardEvent>` called with that command, also stops compiling. Detect lists these shapes and the error, and Migration shows inferred listeners and a generic helper. - v0.48.0, #8829: not listed at all. `registerList` handles Backspace at `COMMAND_PRIORITY_BEFORE_EDITOR`, before rich text: at the start of a top-level item it turns the item into a paragraph and splits the list, where it used to join it to the item above. It is now a behavior change with a Verify line. `ListItemNode.collapseAtStart` also widened its return type from `true` to `boolean`; the entry says why that is not filed as breaking. To keep this from recurring, `.changeset/README.md` gets a "Type signature changes" section: a type change that can make existing call sites stop compiling is `[breaking]` even when it only deprecates something, and its Detect names the call shapes, including callers that rely on an inferred type argument. AGENTS.md and CONTRIBUTING.md, which already summarize the changeset format, get one paragraph each. `pnpm run check-changesets` now warns (without failing) when a `[deprecation]` or `[chore]` entry mentions a type parameter, overload, generic, return or payload type, or signature and has no `Detect:` paragraph. The pattern also covers "type params", "branded", "invariant", "narrowed return/payload" and "now returns". Neither the pending changesets nor the curated `[deprecation]` and Other entries in CHANGELOG.md trigger it. Out of scope: `packages/lexical-list/flow/LexicalList.js.flow` still declares `collapseAtStart(selection: RangeSelection): true`. Changing it is a published Flow type change that needs its own changeset. ## Changeset None needed: documentation and changeset tooling only. ## Test plan The new CHANGELOG.md wording was checked against the declarations at the v0.45.0, v0.46.0, v0.48.0 and v0.49.0 tags, and the TypeScript errors and the Migration snippets were compiled against the current sources. The list Backspace change was checked with a scratch unit test (not committed) that presses Backspace at the start of the second of three items, with and without `ListExtension`: `["list:first","paragraph:second","list:third"]` with it, and `["list:firstsecond|third"]` with rich text alone, which is what v0.47 did. ### Before With the test changes applied but not the CHANGELOG.md and `entry.mjs` changes: ``` $ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts × warns when a deprecation or chore changes types without Detect 4ms × parses the repository CHANGELOG.md 15ms FAIL |scripts-unit| scripts/__tests__/unit/changelog.test.ts > parseChangelog > parses the repository CHANGELOG.md AssertionError: expected { behavior: 43, breaking: 35, …(1) } to deeply equal { behavior: 44, breaking: 35, …(1) } FAIL |scripts-unit| scripts/__tests__/unit/changesets.test.ts > changeset entry format > warns when a deprecation or chore changes types without Detect AssertionError: expected { errors: [], warnings: [] } to deeply equal { errors: [], warnings: [ …(1) ] } Test Files 2 failed (2) Tests 2 failed | 63 passed (65) ``` ### After ``` $ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts Test Files 2 passed (2) Tests 65 passed (65) $ pnpm run check-changesets Changeset check passed: 80 pending changeset(s) valid. ``` Prettier and ESLint pass on the changed files.
…raversal and v0.48 list Backspace changelog entries ## Description Review follow-ups for the changelog entries this pull request rewrites: - v0.48.0, #8829: nested list items were already outdented by `@lexical/rich-text` before #8829 (a nested `ListItemNode` reports its depth as its indent). The entry now says what changed: Backspace at the start of a top-level item used to join it to the block above, either the previous item or a paragraph before the list, and now turns it into a paragraph. - v0.46.0, #8661: Detect quotes the TypeScript errors each call shape produces (TS2322, TS2345, and TS2740 for a return value). - `.changeset/README.md`: the type-signature example uses `getFirstChildOrThrow()`, since `getFirstChild()` returns `T | null` and its argument case already failed under `strict`. ## Test plan The quoted errors come from compiling the four call shapes (annotated `getFirstChild()`, annotated `getChildren()`, `getFirstChildOrThrow()` as an argument, and as a return value) against the current declarations, whose non-generic overloads are the ones v0.46.0 added: ``` t.ts(5,7): error TS2322: Type 'LexicalNode | null' is not assignable to type 'ParagraphNode | null'. t.ts(6,7): error TS2322: Type 'LexicalNode[]' is not assignable to type 'ListItemNode[]'. t.ts(7,12): error TS2345: Argument of type 'LexicalNode' is not assignable to parameter of type 'ListNode'. t.ts(9,3): error TS2740: Type 'LexicalNode' is missing the following properties from type 'ListNode': __tag, __start, __listType, getTag, and 68 more. ``` A scratch unit test (not committed) pressing Backspace at the start of the first item of a list that follows a paragraph prints `["paragraph:para","paragraph:first","list:second"]` with `ListExtension` and `["paragraph:parafirst","list:second"]` with rich text alone. ### Before Same tests as the previous commit: ``` $ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts Test Files 2 passed (2) Tests 65 passed (65) ``` ### After ``` $ pnpm vitest run scripts/__tests__/unit/changesets.test.ts scripts/__tests__/unit/changelog.test.ts Test Files 2 passed (2) Tests 65 passed (65) $ pnpm run check-changesets Changeset check passed: 80 pending changeset(s) valid. ```
Description
Pressing Backspace at the start of a list item currently falls through to
deleteCharacter, which merges the item with the previous block. This deletes the list formatting and, when a DecoratorNode precedes the list, deletes the decorator entirely. The expected behavior (matching Google Docs, Notion, and Apple Pages) is: indented items outdent one level, and top-level items convert to a paragraph, splitting the list if the item is in the middle.This PR adds a
KEY_BACKSPACE_COMMANDhandler atCOMMAND_PRIORITY_BEFORE_EDITORthat intercepts Backspace when the caret is at offset 0 of a list item. A walk-up loop from the anchor node finds the enclosingListItemNode, then$handleListBackspaceAtStarteither calls$handleOutdent(indented items) or converts the item to a paragraph with$copyNode-based list splitting (top-level items). Empty non-first items are just removed with the cursor placed at the end of the previous sibling, matching the merge behavior ofdeleteCharacter.ListItemNode.collapseAtStartis also updated to match, sincebeforeinput'sdeleteContentBackwarddispatchesDELETE_CHARACTER_COMMANDdirectly — bypassingKEY_BACKSPACE_COMMAND— and reachescollapseAtStartthrough the$collapseAtStartwalk inLexicalSelection.ts.The existing
$handleListItemBackspaceAdjacentToDecorator(#5072) is kept as-is. Its decorator-adjacent guard fires first for that specific case; the new handler covers everything else. A follow-up cleanup is tracked separately.Closes #6334
Test plan
$handleListBackspaceAtStart: single-item list, multi-item first, indented outdent, indented with siblings, middle item split, last item, empty middle (removed), empty indented (outdented)pnpm test-unit— lexical-list 118/118, full suite passCharacterLimite2e regression caught and fixed — empty non-first items now defer to merge instead of paragraph conversion