marktext / marktext/marktext

[Bug] Cmd+Backspace across two blocks detaches the second block, and Enter on a list then throws "Failed to execute 'insertBefore'"

Open
#5,415 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🐛 bug 🔭 area/muya 🚧 needs triage
Dominant language
TypeScript
Stars
61.6k
Forks
4.6k
Avg merge
23h 49m
Merged PRs (30d)
89

Description

Description

Deleting a selection that spans two blocks with Cmd+Backspace removes the second block on screen but not from the document. The block stays in the editor's block tree with its element gone, so a later Enter, Enter at the end of a bullet list opens the "Unexpected renderer process error" dialog with NotFoundError: Failed to execute 'insertBefore' on 'Node'. Other edits that never reach the editor's key handling behave the same way. This is one of the triggers behind #5035.

Steps to Reproduce
  1. Create a file with:
    - one
    - two
    
    text
    
  2. Open it in MarkText.
  3. Click between tw and o in two.
  4. Hold Shift and click between te and xt in text (or press Shift+), so the selection runs from the list item into the paragraph.
  5. Press Cmd+Backspace.
  6. Click at the end of the bullet line, press Enter, then press Enter again.
Expected Behavior

The bullet reads twxt and text is removed from the document as well. The second Enter leaves an empty paragraph below the list. No error.

Actual Behavior
  • After step 5 the bullet shows twxt and the text line disappears from the screen, but the document (and the saved file) is still - one / - twxt / blank line / text.
  • The second Enter in step 6 opens the "Unexpected renderer process error" dialog.

The same happens, over the same selection, with:

  • Ctrl+K, Ctrl+D, Ctrl+H and Ctrl+Y on macOS (checked in a Chromium test page, not in the packaged app);
  • text committed without a key press, such as the emoji picker (Ctrl+Cmd+Space), dictation or handwriting input (reproduced with synthetic text input; the real macOS emoji picker was not checked).
Screenshots / Logs
NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
    at ScrollPage.insertBefore
    at ScrollPage.insertAfter
    at ParagraphContent._enterInListItem
    at ParagraphContent.enterHandler
    at ParagraphContent.keydownHandler
Operating System

macOS

MarkText Version

0.20.0-rc.3 (also reproduced on the current develop branch)

OS Version

macOS 27.0 (arm64)

Reproducibility
  • I can reliably reproduce this issue
Related
  • #5035: the same crash; this is one of its triggers.
  • #5381 carried a fix for this before it was narrowed to the setext heading trigger.

Possible cause: muya cuts a selection that spans blocks only in its document keydown handler (packages/muya/src/clipboard/index.ts), and shouldCrossBlockCut deliberately skips keys pressed with Cmd or Ctrl. Input that has no keydown at all never reaches that handler either. Chromium then applies the edit itself across the block elements and deletes the ones in between. A prototype that runs the same cut from a beforeinput handler fixed every route above in Chromium.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/muya/src/clipboard/index.ts and trace the selection-cut handling alongside the reported ScrollPage and ParagraphContent stack entries. Reproduce the cross-block edit and then Enter sequence in MarkText, including input without a keydown. Done means the second block is removed from the document and saved file, the list can be exited with Enter, and no renderer error occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, typescript
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.