[Bug] Deleting a selection that ends in a table inside a list or quote also deletes every block after it · Issue #5400 · marktext/marktext · GitHub
Skip to content

[Bug] Deleting a selection that ends in a table inside a list or quote also deletes every block after it #5400

Closed

Description

@Jocs

Description

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

  1. Open a document with:
    - a
    
      | t |
      | --- |
      | 1 |
    
    after
    
    more
    
    # heading
  2. Click right after a.
  3. Press Shift+↓ twice. The selection now ends at the start of the cell 1.
  4. 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

Operating System

macOS

MarkText Version

0.20.0-rc.2, develop @ 0e156b0

OS Version

macOS 27.0

Reproducibility

  • I can reliably reproduce this issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions