Repository navigation
fix(muya): collapse only the nested code block when a cut starts in its language line (#5368) - #5370
Merged
Merged
Conversation
…ts language line (#5368) A cut that starts in a code block's language line collapses that code block into a paragraph (#918). `collapseLanguageInputCut` replaced `startBlock.outMostBlock`, which for a code block inside a list item or a block quote is the whole list or quote, so every other item or quote paragraph was deleted with it, including content outside the selection: Shift+Down from the end of the language box in a list item, then typing, left a single paragraph. Replace the code block itself. At the top level the code block is the outermost block, so nothing changes there. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop
This was referenced Sep 15, 2026
`getAnchor()` is how muya names the whole block a content leaf belongs to (`pruneAfterBranch`, `_immediateBlockAtCursor`). For a language input it is its code block, so `collapseLanguageInputCut` no longer relies on the language input being the code block's direct child. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop
This was referenced Sep 16, 2026
Closed
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 #5368
Summary
When a code block sits inside a list item or block quote, replacing a selection that starts in its language box (typing, pasting or Backspace) replaced the whole list or quote with one paragraph, deleting every other item or quote paragraph, including content outside the selection. Shift+↓ from the end of the language box selects exactly such a range.
A cut that starts in a language line collapses its code block into a paragraph (#918).
collapseLanguageInputCut()(packages/muya/src/clipboard/cut.ts) replacedstartBlock.outMostBlockwith that paragraph; for a nested code block that is the list or quote. Replace the code block itself (startBlock.getAnchor()). At the top level the code block is the outermost block, so the #918 behaviour there is unchanged.Steps to reproduce
Checked in the released MarkText 0.20.0-rc.2 (macOS) and in a desktop build of this branch, with real mouse and keyboard input.
jsshows, then click right afterjs.q.jsqnst a = 1(the list,item oneanditem twoare gone)- item one/jsqnst a = 1/- item twoThe same with a quote (
> quote/ code block /> tail, select from the language into the code, Backspace): develop leaves only the merged paragraph; this PR keepsquoteandtailin the quote.Type of change
Test plan
clipboard/__tests__/cutNestedLanguageInput5368.spec.ts: cut into its own code in a list and in a quote, cut ending in a paragraph after the list (the content before the code block survives), and the top-level Code block no longer be input #918 case. Each checks the json state against the block tree. The 3 nested cases fail ondevelop; the top-level control passes on both.editing/cut-nested-language-input-5368.spec.ts(types over the selection with the real keyboard). Fails ondevelop, passes with the fix (3/3 repeated)._electron, real click + Shift+↓ + typing): the table above, 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.Notes for reviewers
Found while testing, not changed here: a cross-block cut that starts inside a list or quote and ends after it does not remove the selected rest of that list or quote. For
- a/- b/- c/tail, selecting fromatotailand cutting leaves- aail/- b/- c:removeBlocksonly removes siblings at the level of the shared container, not the siblings after the start block inside its own list item and list. With this PR the same applies when such a cut starts in a nested language line.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