Skip to content

fix(muya): collapse only the nested code block when a cut starts in its language line (#5368) - #5370

Merged
Jocs merged 2 commits into
developfrom
fix/5368-nested-language-cut
Sep 15, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/5368-nested-language-cut

Conversation

@Jocs

@Jocs Jocs commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

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) replaced startBlock.outMostBlock with 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.

  1. Open a document with:
    - item one
    
      ```js
      const a = 1
      ```
    
    - item two
  2. Click in the code line so the language box js shows, then click right after js.
  3. Press Shift+↓ and type q.
Saved markdown
0.20.0-rc.2 jsqnst a = 1 (the list, item one and item two are gone)
This PR - item one / jsqnst a = 1 / - item two

The same with a quote (> quote / code block / > tail, select from the language into the code, Backspace): develop leaves only the merged paragraph; this PR keeps quote and tail in the quote.

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 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 on develop; the top-level control passes on both.
  • New e2e spec editing/cut-nested-language-input-5368.spec.ts (types over the selection with the real keyboard). Fails on develop, passes with the fix (3/3 repeated).
  • Existing Code block no longer be input #918 / Unexpected error with message Cannot insert into out of bounds index #4903 cut specs still pass.
  • Real desktop app (Playwright _electron, real click + Shift+↓ + typing): the table above, on the packaged 0.20.0-rc.2 and on a build:unpack of this branch.
  • muya: vitest run 235 files / 1667 tests; lint:types, eslint on the changed files and check-circular pass.
  • Manually tested on: macOS

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 from a to tail and cutting leaves - aail / - b / - c: removeBlocks only 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

…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
`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
@Jocs
Jocs merged commit 555f3a7 into develop Sep 15, 2026
7 checks passed
@Jocs
Jocs deleted the fix/5368-nested-language-cut branch September 15, 2026 15:16
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] Cutting from a nested code block's language box replaces the whole list or quote

1 participant