[Bug] Cutting a selection that ends in a code block's language box duplicates text and removes the language box · Issue #5371 · 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] Cutting a selection that ends in a code block's language box duplicates text and removes the language box #5371
Replacing a selection that ends inside a code block's language box (typing, pasting or pressing Backspace over it) corrupts that code block:
the part of the language after the caret is copied into the paragraph where the selection starts, while the code block keeps its full language, so the text appears twice;
the code block loses its language box: it is gone from the editor, the language can no longer be edited, and undo does not bring it back until the document is reopened;
when the code block is inside a list item, the paragraphs between the start of the selection and the code block are not removed.
Shift+↓ from a paragraph above a code block puts the end of the selection in its language box.
Steps to Reproduce
Open a document with:
intro
- item
```js
code
```
tail
Click between in and tro.
Press Shift+↓ twice (the selection now ends at the start of the language box js), then press Backspace.
Click in the code line: there is no language box above it any more.
Top-level variant: Intro paragraph / ```js code block / Outro; select from Int|ro paragraph to j|s and type X.
Expected Behavior
The selection ends inside the code block's language line, so that code block stays with its code and its language box; only the selected part of the language is removed, and nothing from the language is merged into the paragraph:
Document
Selection
Expected
nested (above)
`in
tro→
top-level
`Int
ro paragraph→j
Actual Behavior
Measured with real mouse and keyboard input in MarkText 0.20.0-rc.2 on macOS, and on develop @ 8bcb1e0 (muya e2e host):
Document
Result
nested
saved injs / - item / code block ```js / tail: js is duplicated, the selected item is kept, and the code block has no language box
top-level
saved IntXs / code block ```js / Outro: s is duplicated, and the code block has no language box, also after undo
No error is shown.
Screenshots / Logs
Analysis: the cross-block cut in cutSelection() (packages/muya/src/clipboard/cut.ts) merges endBlock.text.substring(endOffset) into the start block and then calls removeBlocks(startBlock, endBlock). With the language box as endBlock, the merged text is the rest of the language, and pruneAfterBranch removes the language box node itself (a content leaf, so no json op is sent) plus nothing before it inside the list item. muyajs never removed a language input (removeTextOrBlock skips it).
Activity
fix(muya): keep the code block when a cut ends in its language line (#…
fix(muya): keep the code block when a cut ends in its language line (#…
fix: keep code blocks and tables intact when a cut crosses into or ou…
fix: keep code blocks and tables intact when a cut crosses into or ou…
fix: keep code blocks and tables intact when a cut crosses into or ou…