Repository navigation
fix(muya): remove the selected rest of a list or quote when a cut starts in it (#5385) - #5397
Merged
Merged
Conversation
…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
This was referenced Sep 15, 2026
Merged
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 #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)inpackages/muya/src/clipboard/cut.ts.removeBlocksdid two things: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 ofpruneAfterBranch. Walking up from the start to the start branch, it removes the blocks that follow each node, as muyajs'removeBlocksdid.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.aand press Shift+↓ three times. The selection runs to the end oftail.a, press Enter twice and choose Edit › Paste.For the quote, use
> a/>/> b/ (blank line) /tailand press Shift+↓ twice.develop- a/- b/- c- a> a/>/> b> a- a/- b/- c- aabandcin the document twiceb,candtailonceType of change
Test plan
clipboard/__tests__/cutRestOfContainer5385.spec.ts(7 cases). Each checks the markdown and that the json state matches the block tree. All 7 fail ondevelop. The cases:editing/cut-rest-of-container-5385.spec.ts: Backspace over the list selection and typing over the quote selection, with the real keyboard. It fails ondevelopand passes with the fix (3/3 repeated).clipboard,selection,table-rect-clipboardandundo-redo._electron): the table above, on the packaged 0.20.0-rc.2, abuild:unpackofdevelopand abuild:unpackof this branch.vitest run1682 tests;lint:types, eslint on the changed files andcheck-circularpass.Notes for reviewers
removeBlocksIntoTable) or starts inside a table cell goes through separate code. Neither is changed here.-line: the empty-line in the pasted content comes from copying a selection that starts at the end ofa. 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