Skip to content

fix(muya): remove the selected rest of a list or quote when a cut starts in it (#5385) - #5397

Merged
Jocs merged 1 commit into
developfrom
fix/5385-cut-rest-of-container
Sep 15, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/5385-cut-rest-of-container

Conversation

@Jocs

@Jocs Jocs commented Sep 15, 2026

Copy link
Copy Markdown
Member

Closes #5385

Summary

Replacing a selection that starts inside a list or quote and ends in a block after it kept the selected rest of that list or quote. Backspace, typing, pasting over the selection and Cut are all affected. With Cut, those items were also on the clipboard, so Cut + Paste put them into the document twice.

A cross-block cut merges the text around the selection into the start block and calls removeBlocks(startBlock, endBlock) in packages/muya/src/clipboard/cut.ts. removeBlocks did two things:

  • removed the siblings strictly between the start branch and the end branch, inside their lowest common container;
  • pruned the end side with pruneAfterBranch.

Nothing handled the start side, so the blocks after the start leaf inside its own list item, list or quote stayed. The same gap kept a sub-list that a cut passes over inside a single list.

The new pruneBeforeBranch() is the start-side counterpart of pruneAfterBranch. Walking up from the start to the start branch, it removes the blocks that follow each node, as muyajs' removeBlocks did.

The walk starts at the whole block the start leaf belongs to (getAnchor()). That keeps two things intact:

Steps to reproduce

Checked in the released MarkText 0.20.0-rc.2 (macOS), in a desktop build of develop @ e542262 and in a desktop build of this branch, with real mouse, keyboard and menu input.

  1. Open a document with:
    - a
    - b
    - c
    
    tail
  2. Click right after a and press Shift+↓ three times. The selection runs to the end of tail.
  3. Press Backspace. For the Cut variant, choose Edit › Cut instead, then click after a, press Enter twice and choose Edit › Paste.

For the quote, use > a / > / > b / (blank line) / tail and press Shift+↓ twice.

Case 0.20.0-rc.2 / develop This PR
list, Backspace - a / - b / - c - a
quote, Backspace > a / > / > b > a
list, Cut - a / - b / - c - a
list, Cut, then Paste after a b and c in the document twice b, c and tail once

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

Notes for reviewers

  • Out of scope: a cut that ends inside a table (removeBlocksIntoTable) or starts inside a table cell goes through separate code. Neither is changed here.
  • Pasted - line: the empty - line in the pasted content comes from copying a selection that starts at the end of a. It is the same before and after this change.

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

…rts in it (#5385)

A cross-block cut merges the text around the selection into the start block
and calls `removeBlocks`. That removed the siblings between the start and
end branches and pruned the end side, but nothing after the start leaf
inside its own list item, list or quote. Backspace, typing or Cut over a
selection from inside a list to a paragraph after it kept the selected later
items, and Cut + Paste put them into the document twice.

Remove the blocks that follow the start inside each of its containers below
the start branch, mirroring what the end side does for the blocks before the
end, as muyajs' `removeBlocks` did. The walk starts at the whole block the
start leaf belongs to (`getAnchor()`), so a code block's inner nodes, which
share its json path, and a table's grid are never removed on their own.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WEPLCvFTgbYf35z85XUJop
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] Deleting a selection from inside a list or quote to a block after it keeps the selected rest of the list or quote

1 participant