Skip to content

fix: keep heading type on first line when splitting after Shift+Enter - #965

Closed
BetterAndBetterII wants to merge 1 commit into
mdx-editor:mainfrom
BetterAndBetterII:fix/heading-linebreak-split
Closed

BetterAndBetterII wants to merge 1 commit into
mdx-editor:mainfrom
BetterAndBetterII:fix/heading-linebreak-split

Conversation

@BetterAndBetterII

Copy link
Copy Markdown

Summary

  • Lexical HeadingNode.insertNewAfter treats any text offset === 0 as the start of the heading, so Enter after a Shift+Enter linebreak moves the heading onto the latter fragment and downgrades the first line to a paragraph.
  • Override insertNewAfter in headingsPlugin so a split after a linebreak keeps the first half as a heading, inserts a paragraph for the second half, and drops the leftover break. Start/end Enter behavior is unchanged.

Fixes #925

Test plan

  • npx vitest --run src/test/headings.test.tsx (split after linebreak, Enter at start, Enter at end)
  • npx vitest --run src/test/markdown-shortcut.test.tsx src/test/core.test.tsx

Lexical HeadingNode.insertNewAfter treats any text offset 0 as the start
of the heading, so Enter after a linebreak moves the heading onto the
latter fragment. Override insertNewAfter for that case so the first half
stays a heading and the second becomes a paragraph.

Fixes mdx-editor#925
@petyosi

petyosi commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Thank you for investigating this and for the detailed tests. Since the same behavior reproduces in the official Lexical Playground, the fix belongs in Lexical's HeadingNode.insertNewAfter implementation. I don't want MDXEditor to override HeadingNode.prototype globally as a workaround. Please submit the fix and regression test upstream to Lexical. Once the fix is merged and released there, I will upgrade MDXEditor's Lexical dependencies to include it.

@petyosi petyosi closed this Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Heading type incorrectly transfers to the latter fragment when splitting a heading containing a line break

2 participants