Skip to content

[Bug] Backspace at the start of a top-level footnote merges it into the previous paragraph and leaves an empty definition #5343

Closed

Description

@Jocs

Description

Backspace at the start of a footnote definition behaves differently depending on where the footnote is, and at the top level it leaves the document in an odd state:

Where the footnote is Backspace at the start of its first paragraph
Top level, after a paragraph note is merged into the previous paragraph, and an empty definition [^1]: is left behind
Top level, first block of the document Nothing happens
Inside a blockquote The footnote wrapper is removed and note stays as a plain paragraph in the quote
Inside a list item Throws Cannot use numerical key for object container (#5340)

Backspace at the start of a blockquote removes the quote wrapper; a footnote definition should work the same way everywhere.

Related: #5340 (same key, footnote inside a list item).

Steps to Reproduce

  1. Preferences → Markdown → Extensions → turn on Footnote.
  2. Open a document with:
    x
    
    [^1]: note
  3. Click in note, move the caret to the start of it, and press Backspace.
  4. Switch to source code mode.

Also try a document that starts with the definition ([^1]: note as the first line) and press Backspace at the start of note.

Expected Behavior

Backspace at the start of the first paragraph of a footnote definition removes the footnote wrapper: its paragraphs stay in place as plain paragraphs and the caret stays at the start of note. For the example above the result is x\n\nnote. The same happens when the footnote is the first block of the document, inside a blockquote, or inside a list item.

Actual Behavior

  • After a paragraph: the markdown becomes xnote\n\n[^1]: (merged into x, empty definition left).
  • As the first block: nothing happens.

Screenshots / Logs

State after Backspace (from muya.editor.jsonState.getState()), footnote after a paragraph:

before: paragraph "x", footnote[1]( paragraph "note" )
after:  paragraph "xnote", footnote[1]( )

Analysis: ParagraphContent.backspaceHandler() (packages/muya/src/block/content/paragraphContent/index.ts) has no footnote case. _paragraphParentType() only recognizes block-quote / list-item / task-list-item ancestors, so a top-level footnote paragraph is handled as a plain paragraph and merged into the previous content block (leaving the emptied footnote), and at the start of the document there is no previous block, so nothing happens. Inside a blockquote the footnote is only unwrapped because the block-quote handler happens to treat the footnote as the quote.

Reproduced in real Chrome against the muya e2e host.

Operating System

macOS

MarkText Version

develop @ 2164c58 (the code involved is unchanged since v0.20.0-rc.2)

OS Version

macOS 27.0

Reproducibility

  • I can reliably reproduce this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bug🔭 area/muya🚧 needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions