Repository navigation
fix(muya): change the heading level of the caret's paragraph, not its list (#5360) - #5361
Merged
Merged
Conversation
… 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
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 #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()handledupgrade heading/degrade headingwith_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, andreplaceBlockByLabelreplaced 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'sparent). 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).
item two.- item one/- item two(item two)###### item one- item one/- ###### item two> quote line/>/> second(second)###### quote line> quote line/>/> ###### second1. one/2. two/- nested(nested)###### one1. one/2. two/- ###### nested- item one/- ## item two(item two)- item one/- ### item twotext###### 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>ondevelop; with this PR nothing changes. The Paragraph menu is disabled there, so only the palette reaches it.Type of change
Test plan
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. Ondevelopthe 8 bug cases fail and the 3 controls pass.editing/heading-level-caret-block-5360.spec.ts(list: Promote, type, Demote; quote; table cell). All 3 fail ondevelopand pass with the fix._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 abuild:unpackof this branch.vitest run233 files / 1659 tests;lint:types, eslint on the changed files andcheck-circularpass.Notes for reviewers
Not changed here: a setext heading (
Title+---) still counts as level 0, so Promote turns a level-2 setext heading into###### Titleand 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