[Bug] Deleting a selection from inside a list or quote to a block after it keeps the selected rest of the list or quote · Issue #5385 · marktext/marktext · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Deleting a selection from inside a list or quote to a block after it keeps the selected rest of the list or quote #5385
Deleting or cutting a selection that starts inside a list or quote and ends in a block after it leaves the selected rest of that list or quote in the document. The block where the selection ends is removed, but the list items or quote paragraphs between the start of the selection and the end of the container stay, even though they were inside the selection.
With Cut, those items are also copied to the clipboard, so cutting and pasting the selection elsewhere puts them into the document a second time.
This affects every edit that replaces a cross-block selection: Backspace, Delete, typing, pasting over it and Cut. No error is shown, and the saved document matches what the editor shows.
Steps to Reproduce
Open a document with:
- a
- b
- c
tail
Click right after a.
Press Shift+↓ three times. The selection now runs from after a to the end of tail.
Press Backspace.
Cut variant: at step 4 choose Edit › Cut, then click after c, press Enter twice and choose Edit › Paste.
Quote variant: the same with > a / > / > b / (blank line) / tail, pressing Shift+↓ twice.
Expected Behavior
Everything inside the selection is removed:
Document
Action
Expected
list
Backspace
- a
quote
Backspace
> a
list
Cut, then Paste below
- a after the cut; the pasted content appears once
Actual Behavior
Measured with real mouse, keyboard and menu input, using Playwright _electron, in MarkText 0.20.0-rc.2 on macOS and in a desktop build of develop @ e542262. Both give the same result:
Document
Action
Saved markdown
list
Backspace
- a / - b / - c (b and c kept)
quote
Backspace
> a / > / > b (b kept)
list
Cut
document - a / - b / - c; clipboard - / - b / - c / tail
list
Cut, then Paste below c
- a / - b / - c / - / - b / - c / tail (b and c twice)
At the engine level, the same happens for every container the selection can start in. Each row below selects from after a to after the t of tail, except the last, which selects to after x:
Document
develop
Expected
1. a / 2. b / tail
1. aail / 2. b
1. aail
- a / - b / - c / tail
- aail / - b / - c
- aail
- a with a second paragraph more / tail
- aail / more
- aail
- a / - b / 1. x / 2. y (end after x)
- a / - b / 1. y
- a / 1. y
A selection inside one list, or from a paragraph into a list, is handled correctly.
Screenshots / Logs
Analysis: a cross-block cut merges the text before the selection start and after its end into the start block, then calls removeBlocks(startBlock, endBlock) in packages/muya/src/clipboard/cut.ts. removeBlocks handles two parts:
the siblings strictly between the start branch and the end branch, inside their lowest common container;
the end side, via pruneAfterBranch.
Nothing handles the start side. The blocks that follow the start leaf inside its own list item, list or quote, below that common container, are never removed.
The legacy muyajs removeBlocks (packages/muyajs/lib/contentState/index.js) did remove them. It walked before's following siblings, and recursed to before's parent whenever after was not among them.
Activity
fix(muya): remove the selected rest of a list or quote when a cut sta…