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 that ends in a table inside a list or quote also deletes every block after it #5400
Deleting a selection that ends inside a table which is not a top-level block also deletes content outside the selection. That covers a table inside a list item or a quote, and any edit that replaces the selection: Backspace, typing over it or Cut.
Every top-level block after the block where the selection starts is deleted, up to the end of the document. When the table is inside a quote after that block, the quote holding the table is deleted too. The editor then throws Cannot destructure property 'path' of 'this.parent' as it is null. and no longer shows what is saved.
Steps to Reproduce
Open a document with:
- a
| t || --- || 1 |
after
more
# heading
Click right after a.
Press Shift+↓ twice. The selection now ends at the start of the cell 1.
Press Backspace.
after, more and # heading disappear from the editor and from the saved document.
Variant with the table in a quote: use the steps above with
- a
> | t |> | --- |> | 1 |
after
An "Unexpected error" appears, and the quote and after are gone.
Expected Behavior
Only the selection is removed. Everything after it stays: after, more, # heading, and the quote holding the table.
Actual Behavior
Measured with real mouse and keyboard input, using Playwright _electron, in MarkText 0.20.0-rc.2 on macOS and in a desktop build of develop @ 0e156b0. Both give the same result:
Where the table is
Saved markdown after Backspace
Error
in the list item, followed by after, more, # heading
- a1 / an empty table; after, more and # heading deleted
none
in a second item - b, followed by after
- a1 / - b / an empty table; after deleted
none
in a quote after the list, followed by after
- a1; the quote with the table and after deleted; the editor shows only a
Cannot destructure property 'path' of 'this.parent' as it is null.
The emptied cells keep showing their text (#5398), and - b in the second row is kept although it was selected (#5399).
Screenshots / Logs
Analysis:removeBlocks() in packages/muya/src/clipboard/cut.ts hands a selection that ends in a table to removeBlocksIntoTable(). That function removes "every outmost block strictly between before's outmost block and the table" by walking before.outMostBlock.next until it reaches the table.
A table inside a list item or a quote is never one of those top-level blocks, so the walk never stops. It removes every block after the start's outermost block, including a quote that holds the table. The cells of that now detached table are then emptied, and get path throws:
TypeError: Cannot destructure property 'path' of 'this.parent' as it is null.
at get path
at set text
at emptyCellContentsUntil
at removeBlocksIntoTable
at removeBlocks
Activity
fix(muya): keep the document intact when a cut ends in a table (#5400, …
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…