[Bug] Backspace before an ATX heading's text shows "#Heading", but the document and saved file keep "# Heading" · Issue #5388 · marktext/marktext · GitHub
Skip to content

[Bug] Backspace before an ATX heading's text shows "#Heading", but the document and saved file keep "# Heading" #5388

Closed

Description

@Jocs

Description

With the caret right before the text of an ATX heading, Backspace deletes the space after # on screen, but the document is not updated. The line reads #Heading while still drawn as an H1, the document is not marked modified, and File > Save writes # Heading unchanged. The deletion is silently lost; the screen and the saved file disagree.

Steps to Reproduce

  1. Create h.md with:
    one
    
    # Heading
  2. Open it in MarkText.
  3. Click just before the H of Heading (the # marker appears).
  4. Press Backspace. The line now reads #Heading. Do not type anything else; one more keystroke in the heading hides the problem.
  5. Click at the end of one, then choose File > Save.
  6. Choose View > Source Code Mode, or quit MarkText and open h.md again.

The same happens when a list (- one / - two) comes before the heading.

Expected Behavior

The screen, the unsaved marker and the saved file agree. Removing the space turns the line into the paragraph #Heading (which is what happens as soon as one more character is typed), the document is marked modified, and Save writes #Heading.

Actual Behavior

  • After Backspace the line reads #Heading, still drawn as a large H1.
  • No unsaved marker appears.
  • File > Save writes the file unchanged: one, a blank line, # Heading.
  • Source Code Mode shows # Heading. Switching back shows the H1 with # Heading again.
  • After reopening, the H1 heading Heading is shown; the file still contains # Heading.
  • If one more character (for example X) is typed right after the Backspace, that edit is applied: the line becomes the paragraph #XHeading, the unsaved marker appears, and the file saves and reopens as #XHeading.

Screenshots / Logs

No error is shown.

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

Possible cause (unverified): AtxHeadingContent.backspaceHandler (packages/muya/src/block/content/atxHeadingContent/index.ts) only converts the heading to a paragraph when the caret is before #. With the caret before H, Format.backspaceHandler lets the browser delete the space natively, and the block text and JSON state are not updated or marked dirty until the next input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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