Skip to content

fix(muya): change the heading level of the caret's paragraph, not its list (#5360) - #5361

Merged
Jocs merged 1 commit into
developfrom
fix/5360-heading-level-caret-block
Sep 15, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/5360-heading-level-caret-block

Conversation

@Jocs

@Jocs Jocs commented Sep 15, 2026

Copy link
Copy Markdown
Member

Closes #5360

Summary

Paragraph › Promote Heading (⌘+=) with the caret in a paragraph inside a list or block quote replaced the whole list or quote with one level-6 heading made from its first paragraph, and deleted every other item. Demote Heading on a heading inside a list item did nothing.

Muya.updateParagraph() handled upgrade heading / degrade heading with _changeHeadingLevel(this._outmostBlockAtCursor(), type). For a paragraph in a list or quote the outermost block is the list or quote: its state is not a heading, so its level counted as 0, Promote turned it into level 6, and replaceBlockByLabel replaced the whole block with ###### plus the text of its first leaf. Demote on level 0 is a no-op. The command palette's Upgrade Heading did the same to a table, code block, math block or front matter.

Change the level of the block that holds the caret (_immediateBlockAtCursor()), and only when it is a paragraph or heading, as muyajs did (isAllowedTransformation + converting the caret's parent). Top-level paragraphs and headings behave as before.

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 (the same action as the shortcuts; they are enabled in every list and quote case below).

  1. Open a document with:
    - item one
    - item two
  2. Click in item two.
  3. Press ⌘+= / Ctrl+Plus (Paragraph › Promote Heading).
Document (caret in) Command 0.20.0-rc.2 This PR
- item one / - item two (item two) Promote ###### item one - item one / - ###### item two
> quote line / > / > second (second) Promote ###### quote line > quote line / > / > ###### second
1. one / 2. two / - nested (nested) Promote ###### one 1. one / 2. two / - ###### nested
- item one / - ## item two (item two) Demote unchanged - item one / - ### item two
top-level paragraph text Promote ###### text ###### text (unchanged)

With the caret in a table cell, code block, math block or front matter, Upgrade Heading from the command palette (⌘⇧P) turns that block into ###### <its first line> on develop; with this PR nothing changes. The Paragraph menu is disabled there, so only the palette reaches it.

Type of change

  • Bug fix (non-breaking, fixes an issue)
  • New feature (non-breaking, adds functionality)
  • Breaking change (causes existing functionality to change)
  • Documentation update

Test plan

  • New unit tests in src/__tests__/headingLevelCaretBlock5360.spec.ts (11 cases): list item, heading in a list item (Demote), quote, nested list, caret position after Promote, table / code / math / front matter left unchanged, and top-level paragraph / heading controls. Each checks the json state against the block tree. On develop the 8 bug cases fail and the 3 controls pass.
  • New e2e spec editing/heading-level-caret-block-5360.spec.ts (list: Promote, type, Demote; quote; table cell). All 3 fail on develop and pass with the fix.
  • Real desktop app (Playwright _electron, clicking the menu items with the caret placed by a real click): the table above, on the packaged 0.20.0-rc.2 and on a build:unpack of this branch.
  • muya: vitest run 233 files / 1659 tests; lint:types, eslint on the changed files and check-circular pass.
  • Manually tested on: macOS

Notes for reviewers

Not changed here: a setext heading (Title + ---) still counts as level 0, so Promote turns a level-2 setext heading into ###### Title and Demote does nothing (muyajs gave # Title / ### Title). That is the same before and after this PR.


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

… list (#5360)

Promote / Demote Heading ran `_changeHeadingLevel` on the outermost block
at the caret. For a paragraph in a list or quote that block is the list or
quote itself: it is not a heading, so its level counted as 0, Promote made
it level 6, and `replaceBlockByLabel` replaced the whole list or quote with
`###### ` plus the text of its first paragraph. Every other item was lost.
Demote on a heading inside a list item did nothing for the same reason, and
Upgrade Heading from the command palette turned a table, code block, math
block or front matter into a heading.

Change the level of the block that holds the caret, and only when it is a
paragraph or heading, as muyajs did (`isAllowedTransformation`). A heading
inside a list item or quote now changes in place, and a table or code-like
block is left alone. Top-level paragraphs and headings behave as before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop
@Jocs
Jocs merged commit bff36d7 into develop Sep 15, 2026
7 checks passed
@Jocs
Jocs deleted the fix/5360-heading-level-caret-block branch September 15, 2026 03:15
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] Promote Heading in a list or quote replaces the whole list or quote with a heading

1 participant