[Bug] Backspace before an ATX heading's text shows "#Heading", but the document and saved file keep "# Heading" · Issue #5388 · marktext/marktext · GitHub
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] Backspace before an ATX heading's text shows "#Heading", but the document and saved file keep "# Heading" #5388
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
Create h.md with:
one
# Heading
Open it in MarkText.
Click just before the H of Heading (the # marker appears).
Press Backspace. The line now reads #Heading. Do not type anything else; one more keystroke in the heading hides the problem.
Click at the end of one, then choose File > Save.
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.
Activity
fix(muya): re-read the block type after a Backspace on a syntax marker (