Repository navigation
[lexical-rich-text] Bug Fix: Split a heading on Enter after a line break or an inline decorator - #9295
Merged
etrepum merged 1 commit intoOct 1, 2026
Conversation
…eak or an inline decorator ## Description In a heading, Enter at the start of the text after a line break or an inline decorator turns everything before the caret into a paragraph, and only the text from the caret on stays a heading. That's the caret after Shift+Enter, or just after an inline equation. `HeadingNode.insertNewAfter` reads an anchor offset of 0 as the heading's start, whatever node the anchor is on, and a caret there is at offset 0 of the next text node. The end check beside it has the mirror gap. It compares the anchor with the last descendant's key, but a caret is never on a line break or a decorator. So in a heading that ends with one, Enter at the end adds another heading instead of a paragraph. With this change, `insertNewAfter` reads both edges with `$isAtStartOfNode` and `$isAtEndOfNode` from `@lexical/utils`, which `@lexical/rich-text` already depends on. They check that nothing comes before or after the point inside the heading: - Enter after a line break or an inline decorator splits the heading in two, as it does in the middle of a heading. So does Enter at the start of the text after a link or a bold run, where code can put the caret with `select(0, 0)`. - Enter at the end of a heading that ends with a line break or an inline decorator adds a paragraph, as it does at the end of text. - Enter at the heading's real start still inserts an empty paragraph above. That includes the element point `(link, 0)` in a leading link, and the point before a leading decorator. The middle of a word and the end of text behave as before. Comparing the anchor with the first descendant's key, as the end check did with the last, would also fix the reported cases. At `(link, 0)`, though, it gives an empty heading above instead of an empty paragraph, and one of the new tests covers that. Closes meta#9293 ## Test plan New cases in `LexicalHeadingNode.test.ts` put the caret in a heading and call `insertParagraph()`, which is what Enter runs in rich text. Then they compare each block's type and children. Four cases are the reported shapes. The other five pin what doesn't change: the heading's real start (a text point, `(link, 0)`, and before a leading decorator), the middle of a word, and the end of text. Until now nothing covered Enter at a heading's start, or at the end of a heading that ends with a line break or a decorator. ### Before Trimmed: each test's `|unit| <file> > <describe> >` prefix, the 20 skipped tests, and each failure report down to its diff. Vitest cuts `test.for` names at 40 characters. ``` $ pnpm exec vitest --project unit --no-watch --reporter=verbose packages/lexical-rich-text/src/__tests__/unit/LexicalHeadingNode.test.ts -t "meta#9293" × start of the text after a line break sp… 68ms × just after an inline decorator splits t… 6ms × end of a heading that ends with a line … 5ms × end of a heading that ends with an inli… 3ms ✓ start of the heading adds a paragraph a… 3ms ✓ (link, 0) in a leading link adds a para… 3ms ✓ start of the heading before an inline d… 2ms ✓ middle of a word splits the heading 2ms ✓ end of the text adds a paragraph 2ms FAIL start of the text after a line break sp… - Expected + Received @@ -1,8 +1,8 @@ [ [ - "h1", + "paragraph", "first", "linebreak", ], [ "h1", FAIL just after an inline decorator splits t… - Expected + Received @@ -1,8 +1,8 @@ [ [ - "h1", + "paragraph", "a ", "test_decorator", ], [ "h1", FAIL end of a heading that ends with a line … - Expected + Received @@ -3,8 +3,8 @@ "h1", "first", "linebreak", ], [ - "paragraph", + "h1", ], ] FAIL end of a heading that ends with an inli… - Expected + Received @@ -3,8 +3,8 @@ "h1", "a ", "test_decorator", ], [ - "paragraph", + "h1", ], ] Test Files 1 failed (1) Tests 4 failed | 5 passed | 20 skipped (29) ``` ### After ``` $ pnpm exec vitest --project unit --no-watch --reporter=verbose packages/lexical-rich-text/src/__tests__/unit/LexicalHeadingNode.test.ts -t "meta#9293" ✓ start of the text after a line break sp… 61ms ✓ just after an inline decorator splits t… 4ms ✓ end of a heading that ends with a line … 4ms ✓ end of a heading that ends with an inli… 3ms ✓ start of the heading adds a paragraph a… 3ms ✓ (link, 0) in a leading link adds a para… 3ms ✓ start of the heading before an inline d… 2ms ✓ middle of a word splits the heading 2ms ✓ end of the text adds a paragraph 2ms Test Files 1 passed (1) Tests 9 passed | 20 skipped (29) $ pnpm exec vitest --project browser --no-watch --api.port=63374 --api.strictPort packages/lexical-rich-text Test Files 1 passed (1) Tests 9 passed (9) $ pnpm run test-unit Test Files 369 passed (369) Tests 9020 passed | 1 skipped (9021) ``` `pnpm run tsc` and `pnpm run tsc-test` pass, and prettier and eslint are clean on the changed files. There are no public API or type changes, so no Flow changes. The new tests run in jsdom. Of the browser suites, only `@lexical/rich-text`'s ran, in Chromium. Firefox, WebKit and the e2e suites weren't run. The e2e specs that press Enter in a heading do it at the end of text, in the middle of text, or at the heading's real start (`TextEntry.spec.mjs`), so none of them depends on the old behaviour. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
rinarakaki
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
September 30, 2026 14:59
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
approved these changes
Oct 1, 2026
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
## Description The changes merged since v0.52.0 predate changesets, so without entries the v0.53.0 section would leave them out, including the breaking removal of the deprecated import extensions (#9316). This adds a changeset for every user-facing pull request in v0.52.0..main, written from each pull request, with a `PR: #N` line (they land in this pull request rather than the original ones) and the original author's handle: - breaking: #9316, with the full replacement table as `Migration:` - feature: #9312 - fix: #9335, #9332, #9331, #9328, #9325, #9317, #9321, #9320, #9319, #9283, #9303, #9295, #9291, #9260, #9300, #9301, #9272, #9267, #9302, #9261, #9262, #9263, #9258 - perf: #9264 Skipped as not user-facing: dependency bumps (all devDependencies), website and docs updates, test and CI changes, the private devtools extension and eslint-plugin-internal, and #9353 (a behavior-preserving Flow `Object` to `any` change). It also adds a `[chore]` changeset for this pull request itself, which adds CHANGELOG.md to the `lexical` package's `files`. ## Test plan ### Before ``` $ node scripts/changesets/check.mjs --base origin/main --head HEAD --coverage warn # at the previous commit warning: This pull request changes published code without a changeset for: lexical: packages/lexical/package.json (files) ... Changeset check passed: 0 pending changeset(s) valid; coverage: 1 warning(s), reported only. ``` ### After ``` $ node scripts/changesets/check.mjs --base origin/main Changeset check passed: 27 pending changeset(s) valid; coverage: lexical changed, each named by a changeset. ``` The `latest` release step in a throwaway clone of this branch, with the real tags: ``` $ LATEST_RELEASE=v0.52.0 npm_package_version=0.53.0 node scripts/changesets/release.mjs --date 2026-10-30 Added v0.53.0 to CHANGELOG.md from 27 changeset(s). $ ls .changeset changelog.cjs config.json README.md $ sed -n 1,9p CHANGELOG.md ## v0.53.0 (2026-10-30) ### Breaking changes - **@lexical/code-core, @lexical/code-shiki, @lexical/html, @lexical/link, @lexical/list, @lexical/mdast, @lexical/rich-text, @lexical/table**: Remove the extensions deprecated in v0.52.0 and earlier ([#9316](#9316)) The deprecated import and alias extensions are removed. The `*ImportRules` arrays, including `HorizontalRuleImportRules`, stay. $ grep -n '^### ' CHANGELOG.md | head -7 3:### Breaking changes 28:### Features 36:### Fixes 98:### Performance 102:### Other 106:### Contributors 110:### All changes $ sed -n '/^### Contributors/,+2p' CHANGELOG.md ### Contributors @Tabisharaza, @etrepum, @mbret, @maximilliangrand, @Vedthakar, @rinarakaki, @potatowagon, @followdarko, Gerard Rovira $ sed -n '/^### All changes/,/^## v0.52.0/p' CHANGELOG.md | sed -n '5,6p;$p' | head -2 - [lexical-yjs][Chore] Change last `Object` to `any` in lexical ([#9353](#9353)) Sam Zhou - [lexical-eslint-plugin-internal] Chore: lint window messaging channel scoping ([#9339](#9339)) Sherry ``` (`### All changes` has 50 lines: the 48 commits after v0.52.0, without the `v0.52.0 (#9252)` bump commit, plus this branch's two commits.) Running again before that release PR is merged: ``` $ git tag v0.53.0 # tagged, but CHANGELOG.md on main has no v0.53.0 section $ npm_package_version=0.54.0 node scripts/changesets/release.mjs CHANGELOG.md has no v0.53.0 section, so the v0.53.0 release pull request is not merged yet. Merge it (it consumes the changesets for v0.53.0) before cutting v0.54.0; running again now would put the same changesets in both releases. (exit 1) $ npm_package_version=0.53.1 node scripts/changesets/release.mjs Refusing to release 0.53.1 as a patch: 1 pending [breaking] changeset(s) need a minor release: - .changeset/remove-deprecated-import-extensions.md: Remove the extensions deprecated in v0.52.0 and earlier Run the release with the "minor" increment instead. (exit 1) ``` A prerelease publish (lexical at 0.52.1-nightly.20261016.0, nothing built, so the export check that follows fails as expected): ``` $ node scripts/npm/prepare-release.mjs [lexical] CHANGELOG.md lists pending changes as Unreleased [lexical] package.json references files that are not present in packages/lexical: ./dist/Lexical.dev.js $ sed -n 1,5p packages/lexical/CHANGELOG.md ## Unreleased Merged after the latest stable release and included in 0.52.1-nightly.20261016.0. These entries move into a version section when the next stable release is cut. ### Breaking changes $ git status --short CHANGELOG.md (clean: only the gitignored package copy changed) ```
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
## Description The changes merged since v0.52.0 predate changesets, so without entries the v0.53.0 section would leave them out, including the breaking removal of the deprecated import extensions (#9316). This adds a changeset for every user-facing pull request in v0.52.0..main, written from each pull request, with a `PR: #N` line (they land in this pull request rather than the original ones) and the original author's handle: - breaking: #9316, with the full replacement table as `Migration:` - feature: #9312 - fix: #9335, #9332, #9331, #9328, #9325, #9317, #9321, #9320, #9319, #9283, #9303, #9295, #9291, #9260, #9300, #9301, #9272, #9267, #9302, #9261, #9262, #9263, #9258 - perf: #9264 Skipped as not user-facing: dependency bumps (all devDependencies), website and docs updates, test and CI changes, the private devtools extension and eslint-plugin-internal, and #9353 (a behavior-preserving Flow `Object` to `any` change). Four fixes change observable output or behavior, so their changesets have a `Verify:` paragraph and are listed under Behavior changes: #9303 (new tabs get no `window.opener`), #9272 (imported code content is normalized), #9261 (`$patchStyleText` styles the selection it is given), #9319 (editor keys and namespaces are a counter without a DOM). It also adds a `[chore]` changeset for this pull request itself, which adds CHANGELOG.md to the `lexical` package's `files`. ## Test plan ### Before ``` $ node scripts/changesets/check.mjs --base origin/main --head HEAD --coverage warn # at the previous commit warning: This pull request changes published code without a changeset for: lexical: packages/lexical/package.json (files) ... Changeset check passed: 0 pending changeset(s) valid; coverage: 1 warning(s), reported only. ``` ### After ``` $ node scripts/changesets/check.mjs --base origin/main Changeset check passed: 27 pending changeset(s) valid; coverage: lexical changed, each named by a changeset. ``` The `latest` release step in a throwaway clone of this branch, with the real tags: ``` $ LATEST_RELEASE=v0.52.0 npm_package_version=0.53.0 node scripts/changesets/release.mjs --date 2026-10-30 Added v0.53.0 to CHANGELOG.md from 27 changeset(s). $ ls .changeset changelog.cjs config.json README.md $ sed -n 1,9p CHANGELOG.md ## v0.53.0 (2026-10-30) ### Breaking changes - **@lexical/code-core, @lexical/code-shiki, @lexical/html, @lexical/link, @lexical/list, @lexical/mdast, @lexical/rich-text, @lexical/table**: Remove the extensions deprecated in v0.52.0 and earlier ([#9316](#9316)) The deprecated import and alias extensions are removed. The `*ImportRules` arrays, including `HorizontalRuleImportRules`, stay. $ grep -n '^### ' CHANGELOG.md | head -8 3:### Breaking changes 28:### Behavior changes 54:### Features 62:### Fixes 108:### Performance 112:### Other 116:### Contributors 120:### All changes $ sed -n '/^### Behavior changes/,+7p' CHANGELOG.md ### Behavior changes - **@lexical/link**: Open new-tab links from `ClickableLinkPlugin` / `registerClickableLink` without `window.opener` ([#9303](#9303)) This prevents the opened page from navigating the editor's tab (reverse tabnabbing). Same-tab opens are unchanged. Verify: pages opened from editor links that relied on `window.opener`. $ node scripts/changesets/range.mjs --from 0.52.0 --breaking --json # (kind, [(pr, behavior)]) [('breaking', [(9316, False)]), ('behavior', [(9303, True), (9272, True), (9261, True), (9319, True)])] $ sed -n '/^### Contributors/,+2p' CHANGELOG.md ### Contributors @Tabisharaza, @etrepum, @mbret, @maximilliangrand, @Vedthakar, @rinarakaki, @potatowagon, @followdarko, Gerard Rovira $ sed -n '/^### All changes/,/^## v0.52.0/p' CHANGELOG.md | sed -n '5,6p;$p' | head -2 - [lexical-yjs][Chore] Change last `Object` to `any` in lexical ([#9353](#9353)) Sam Zhou - [lexical-eslint-plugin-internal] Chore: lint window messaging channel scoping ([#9339](#9339)) Sherry ``` (`### All changes` has 50 lines: the 48 commits after v0.52.0, without the `v0.52.0 (#9252)` bump commit, plus this branch's two commits.) Running again before that release PR is merged: ``` $ git tag v0.53.0 # tagged, but CHANGELOG.md on main has no v0.53.0 section $ npm_package_version=0.54.0 node scripts/changesets/release.mjs CHANGELOG.md has no v0.53.0 section, so the v0.53.0 release pull request is not merged yet. Merge it (it consumes the changesets for v0.53.0) before cutting v0.54.0; running again now would put the same changesets in both releases. (exit 1) $ npm_package_version=0.53.1 node scripts/changesets/release.mjs Refusing to release 0.53.1 as a patch: 1 pending [breaking] changeset(s) need a minor release: - .changeset/remove-deprecated-import-extensions.md: Remove the extensions deprecated in v0.52.0 and earlier Run the release with the "minor" increment instead. (exit 1) ``` A prerelease publish (lexical at 0.52.1-nightly.20261016.0, nothing built, so the export check that follows fails as expected): ``` $ node scripts/npm/prepare-release.mjs [lexical] CHANGELOG.md lists pending changes as Unreleased [lexical] package.json references files that are not present in packages/lexical: ./dist/Lexical.dev.js $ sed -n 1,5p packages/lexical/CHANGELOG.md ## Unreleased Merged after the latest stable release and included in 0.52.1-nightly.20261016.0. These entries move into a version section when the next stable release is cut. ### Breaking changes $ git status --short CHANGELOG.md (clean: only the gitignored package copy changed) ```
zurfyx
added a commit
that referenced
this pull request
Oct 15, 2026
## Description The changes merged since v0.52.0 predate changesets, so without entries the v0.53.0 section would leave them out, including the breaking removal of the deprecated import extensions (#9316). This adds a changeset for every user-facing pull request in v0.52.0..main, written from each pull request, with a `PR: #N` line (they land in this pull request rather than the original ones) and the original author's handle: - breaking: #9316, with the full replacement table as `Migration:` - feature: #9312 - fix: #9335, #9332, #9331, #9328, #9325, #9317, #9321, #9320, #9319, #9283, #9303, #9295, #9291, #9260, #9300, #9301, #9272, #9267, #9302, #9261, #9262, #9263, #9258 - perf: #9264 Skipped as not user-facing: dependency bumps (all devDependencies), website and docs updates, test and CI changes, the private devtools extension and eslint-plugin-internal, and #9353 (a behavior-preserving Flow `Object` to `any` change). Four fixes change observable output or behavior, so their changesets have a `Verify:` paragraph and are listed under Behavior changes: #9303 (new tabs get no `window.opener`), #9272 (imported code content is normalized), #9261 (`$patchStyleText` styles the selection it is given), #9319 (editor keys and namespaces are a counter without a DOM). It also adds a `[chore]` changeset for this pull request itself, which adds CHANGELOG.md to the `lexical` package's `files`. ## Test plan ### Before ``` $ node scripts/changesets/check.mjs --base origin/main --head HEAD --coverage warn # at the previous commit warning: This pull request changes published code without a changeset for: lexical: packages/lexical/package.json (files) ... Changeset check passed: 0 pending changeset(s) valid; coverage: 1 warning(s), reported only. ``` ### After ``` $ node scripts/changesets/check.mjs --base origin/main Changeset check passed: 27 pending changeset(s) valid; coverage: lexical changed, each named by a changeset. ``` The `latest` release step in a throwaway clone of this branch, with the real tags: ``` $ LATEST_RELEASE=v0.52.0 npm_package_version=0.53.0 node scripts/changesets/release.mjs --date 2026-10-30 Added v0.53.0 to CHANGELOG.md from 27 changeset(s). $ ls .changeset changelog.cjs config.json README.md $ sed -n 1,9p CHANGELOG.md ## v0.53.0 (2026-10-30) ### Breaking changes - **@lexical/code-core, @lexical/code-shiki, @lexical/html, @lexical/link, @lexical/list, @lexical/mdast, @lexical/rich-text, @lexical/table**: Remove the extensions deprecated in v0.52.0 and earlier ([#9316](#9316)) The deprecated import and alias extensions are removed. The `*ImportRules` arrays, including `HorizontalRuleImportRules`, stay. $ grep -n '^### ' CHANGELOG.md | head -8 3:### Breaking changes 28:### Behavior changes 54:### Features 62:### Fixes 108:### Performance 112:### Other 116:### Contributors 120:### All changes $ sed -n '/^### Behavior changes/,+7p' CHANGELOG.md ### Behavior changes - **@lexical/link**: Open new-tab links from `ClickableLinkPlugin` / `registerClickableLink` without `window.opener` ([#9303](#9303)) This prevents the opened page from navigating the editor's tab (reverse tabnabbing). Same-tab opens are unchanged. Verify: pages opened from editor links that relied on `window.opener`. $ node scripts/changesets/range.mjs --from 0.52.0 --breaking --json # (kind, [(pr, behavior)]) [('breaking', [(9316, False)]), ('behavior', [(9303, True), (9272, True), (9261, True), (9319, True)])] $ sed -n '/^### Contributors/,+2p' CHANGELOG.md ### Contributors @Tabisharaza, @etrepum, @mbret, @maximilliangrand, @Vedthakar, @rinarakaki, @potatowagon, @followdarko, Gerard Rovira $ sed -n '/^### All changes/,/^## v0.52.0/p' CHANGELOG.md | sed -n '5,6p;$p' | head -2 - [lexical-yjs][Chore] Change last `Object` to `any` in lexical ([#9353](#9353)) Sam Zhou - [lexical-eslint-plugin-internal] Chore: lint window messaging channel scoping ([#9339](#9339)) Sherry ``` (`### All changes` has 50 lines: the 48 commits after v0.52.0, without the `v0.52.0 (#9252)` bump commit, plus this branch's two commits.) Running again before that release PR is merged: ``` $ git tag v0.53.0 # tagged, but CHANGELOG.md on main has no v0.53.0 section $ npm_package_version=0.54.0 node scripts/changesets/release.mjs CHANGELOG.md has no v0.53.0 section, so the v0.53.0 release pull request is not merged yet. Merge it (it consumes the changesets for v0.53.0) before cutting v0.54.0; running again now would put the same changesets in both releases. (exit 1) $ npm_package_version=0.53.1 node scripts/changesets/release.mjs Refusing to release 0.53.1 as a patch: 1 pending [breaking] changeset(s) need a minor release: - .changeset/remove-deprecated-import-extensions.md: Remove the extensions deprecated in v0.52.0 and earlier Run the release with the "minor" increment instead. (exit 1) ``` A prerelease publish (lexical at 0.52.1-nightly.20261016.0, nothing built, so the export check that follows fails as expected): ``` $ node scripts/npm/prepare-release.mjs [lexical] CHANGELOG.md lists pending changes as Unreleased [lexical] package.json references files that are not present in packages/lexical: ./dist/Lexical.dev.js $ sed -n 1,5p packages/lexical/CHANGELOG.md ## Unreleased Merged after the latest stable release and included in 0.52.1-nightly.20261016.0. These entries move into a version section when the next stable release is cut. ### Breaking changes $ git status --short CHANGELOG.md (clean: only the gitignored package copy changed) ```
Merged
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In a heading, Enter at the start of the text after a line break or an inline decorator turns everything before the caret into a paragraph, and only the text from the caret on stays a heading. That's the caret after Shift+Enter, or just after an inline equation.
HeadingNode.insertNewAfterreads an anchor offset of 0 as the heading's start, whatever node the anchor is on, and a caret there is at offset 0 of the next text node.The end check beside it has the mirror gap. It compares the anchor with the last descendant's key, but a caret is never on a line break or a decorator. So in a heading that ends with one, Enter at the end adds another heading instead of a paragraph.
With this change,
insertNewAfterreads both edges with$isAtStartOfNodeand$isAtEndOfNodefrom@lexical/utils, which@lexical/rich-textalready depends on. They check that nothing comes before or after the point inside the heading:select(0, 0).(link, 0)in a leading link, and the point before a leading decorator. The middle of a word and the end of text behave as before.Comparing the anchor with the first descendant's key, as the end check did with the last, would also fix the reported cases. At
(link, 0), though, it gives an empty heading above instead of an empty paragraph, and one of the new tests covers that.Fixes #9293
Test plan
New cases in
LexicalHeadingNode.test.tsput the caret in a heading and callinsertParagraph(), which is what Enter runs in rich text. Then they compare each block's type and children. Four cases are the reported shapes. The other five pin what doesn't change: the heading's real start (a text point,(link, 0), and before a leading decorator), the middle of a word, and the end of text. Until now nothing covered Enter at a heading's start, or at the end of a heading that ends with a line break or a decorator.Before
Trimmed: each test's
|unit| <file> > <describe> >prefix, the 20 skipped tests, and each failure report down to its diff. Vitest cutstest.fornames at 40 characters.After
pnpm run tscandpnpm run tsc-testpass, and prettier and eslint are clean on the changed files. There are no public API or type changes, so no Flow changes.The new tests run in jsdom. Of the browser suites, only
@lexical/rich-text's ran, in Chromium. Firefox, WebKit and the e2e suites weren't run. The e2e specs that press Enter in a heading do it at the end of text, in the middle of text, or at the heading's real start (TextEntry.spec.mjs), so none of them depends on the old behaviour.🤖 Generated with Claude Code