fix(muya): cancel Backspace that turns a setext heading into a paragraph (#5035) by Jocs · Pull Request #5381 · marktext/marktext · GitHub
Skip to content

fix(muya): cancel Backspace that turns a setext heading into a paragraph (#5035) - #5381

Merged
Jocs merged 1 commit into
developfrom
fix/5035-cross-block-native-edit
Sep 16, 2026
Merged

Jocs merged 1 commit into
developfrom
fix/5035-cross-block-native-edit

Conversation

@Jocs

@Jocs Jocs commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Summary

Backspace at the start of a setext heading turned the heading into a paragraph in the model, but let the browser's own Backspace run as well. The browser then merged the new paragraph's element into the block above and removed it, so the paragraph stayed in the block tree with a detached element. With a bullet list above the heading, pressing Enter twice at the end of the list threw NotFoundError: Failed to execute 'insertBefore' on 'Node' from ScrollPage.insertBefore ← ScrollPage.insertAfter ← ParagraphContent._enterInListItem — the #5035 crash.

This PR fixes that one trigger and closes #5035. The two other triggers found while investigating it have their own issues, which track the remaining work:

Steps to reproduce

  1. Open a file containing:
    - one
    - two
    
    Heading
    ---
  2. Click at the very start of Heading and press Backspace.
  3. Click at the end of the last bullet line, press Enter, then press Enter again.
  • Expected: Backspace turns the heading into a paragraph in place, and the second Enter leaves an empty paragraph below the list.
  • Actual (v0.20.0-rc.1, v0.20.0-rc.3, develop): after step 2 Heading jumps onto the end of two on screen while the document keeps both (saved as - one / - twoHeading / blank line / Heading), and the second Enter opens the "Unexpected renderer process error" dialog. The same happens with an === underline.

Root cause

SetextHeadingContent.backspaceHandler converts the heading to a paragraph at offset 0 but never calls event.preventDefault(). The ATX heading, paragraph and thematic break handlers all do. The browser's default Backspace then merges the new paragraph's element into the block above.

Fix

Call event.preventDefault() before convertToParagraph, as the ATX heading handler does.

Test plan

Fixes #5035

🤖 Generated with Claude Code

…aph (#5035)

Backspace at the start of a setext heading replaced it with a paragraph
but, unlike the ATX heading, paragraph and thematic break handlers, left
the key's default action running. The browser then merged the new
paragraph into the block above and removed its element, so the paragraph
stayed in the block tree with a detached DOM node. With a bullet list
above the heading, Enter, Enter at the end of the list threw "Failed to
execute 'insertBefore' on 'Node'".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Jocs
Jocs force-pushed the fix/5035-cross-block-native-edit branch from 7b8ae48 to 9321fc5 Compare September 16, 2026 10:24
@Jocs Jocs changed the title fix(muya): stop browser edits from detaching blocks that crash Enter on lists (#5035) fix(muya): cancel Backspace that turns a setext heading into a paragraph (#5035) Sep 16, 2026
@Jocs
Jocs merged commit 5734f01 into develop Sep 16, 2026
7 checks passed
@Jocs
Jocs deleted the fix/5035-cross-block-native-edit branch September 16, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant