{{ message }}
Repository navigation
fix(muya): keep every line when a multi-line block becomes a heading (#5366) - #5367
Merged
Merged
Conversation
…5366) Heading 1-6 and Promote / Demote Heading build the ATX heading with `buildHeadingBlock`, which kept the block's newlines in the heading text. The serializer reads an ATX heading with `/(#{1,6})(.*)/`, so everything after the first newline was dropped on save: `Line one` + Shift+Enter + `line two` turned into `# Line one`, and a two-line setext heading lost its second line on Promote. The editor kept showing the lost text until the document was reopened. Join the lines with a space, as muyajs did and as the heading-to-quote conversion in `Format` already does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop
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.

Closes #5366
Summary
Turning a block whose text has a line break into an ATX heading kept only the first line in the saved file: a paragraph written as
Line oneShift+Enterline twobecame# Line onewith Paragraph › Heading 1, and###### Line onewith Promote Heading; a two-line setext heading lost its second line on Promote. The editor kept showing the second line until the document was reopened.buildHeadingBlock()(packages/muya/src/block/blockTransforms.ts), used byreplaceBlockByLabelfor Heading 1–6 and by Promote / Demote, stored the block's text with its newlines._serializeAtxHeading()reads a heading with/(#{1,6})(.*)/, and.stops at the first newline, so the rest was dropped on save.An ATX heading is a single line, so join the lines with a space, as muyajs did (
newText.replace(/\n/g, ' ')) and asFormatalready does when it turns a heading line into a quote. Single-line blocks are unaffected, and the caret keeps its offset because the text length does not change.Steps to reproduce
Checked in the released MarkText 0.20.0-rc.2 (macOS) and in a desktop build of this branch, by clicking the Paragraph menu items with the caret placed by a real click.
Line one, press Shift+Enter, typeline two.Line one⏎line two# Line one# Line one line twoLine one⏎line two###### Line one###### Line one line twoLine one⏎line two/---# Line one# Line one line twoType of change
Test plan
src/__tests__/headingFromMultilineText5366.spec.ts(4 cases: Heading 1 and Promote on a paragraph with a line break, Promote on a two-line setext heading, Heading 3 on a three-line paragraph). Each checks the json state against the block tree and the saved markdown. All 4 fail ondevelop.editing/heading-from-multiline-text-5366.spec.ts: types the line break with real Shift+Enter, then Heading 2. Fails ondevelop(## first), passes with the fix._electron, menu items): the first two rows of the table on the packaged 0.20.0-rc.2 and on abuild:unpackof this branch.vitest run235 files / 1667 tests;lint:types, eslint on the changed files andcheck-circularpass.By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop