Skip to content

[Bug] Backspace at the start of a footnote inside a list item throws "Cannot use numerical key for object container" #5340

Closed

Description

@Jocs

Description

With the footnote extension enabled, pressing Backspace at the start of a footnote definition that is indented inside a list item throws Cannot use numerical key for object container. The edit is discarded, and every later edit in the document throws the same error until the file is reloaded.

Pressing Enter at the same spot doesn't throw, but it silently nests a new list item directly inside the list item; after reopening the file the footnote is empty and note has become a nested bullet.

Same error message as #4899 / #5018 (fixed by #4913) and #5315, but a different trigger; the stack below has two drop frames, so it is not a proven match for #5315.

Steps to Reproduce

  1. Preferences → Markdown → Extensions → turn on Footnote.
  2. Open a new document, switch to source code mode, and paste:
    - a
    
      [^1]: note
  3. Switch back to the WYSIWYG editor. The footnote definition renders inside the list item.
  4. Click in note and move the caret to the start of it (Cmd+← / Home).
  5. Press Backspace.

Expected Behavior

The footnote is handled as its own container, regardless of the list item around it:

  • Backspace at the start of note removes the footnote wrapper and keeps note as a plain paragraph in the list item: - a\n\n note. This is what already happens today for a footnote inside a blockquote, and what Backspace does at the start of a blockquote. No error, no lost edits.
  • Enter at the start of note inserts an empty paragraph above note inside the footnote, as it does for a top-level footnote or one inside a blockquote. It never creates a list item.

The top-level footnote case (Backspace merges into the previous paragraph and leaves an empty [^1]: ) is tracked in #5343.

Actual Behavior

  • "Unexpected error" dialog (renderer): Cannot use numerical key for object container.
  • The document is unchanged, and any further typing throws the same error.
  • Enter at the start of note instead produces - a\n\n [^1]: \n\n - note (a list item inside the list item).

Screenshots / Logs

Stack from the unminified dev build (@muyajs/core sources):

Error: Cannot use numerical key for object container
    at assert (ot-json1.js)
    at insertChildMut (ot-json1.js)
    at drop (ot-json1.js)
    at drop (ot-json1.js)
    at Object.apply (ot-json1.js)
    at JSONState._apply (packages/muya/src/state/index.ts)
    at JSONState._flushOperationCache (packages/muya/src/state/index.ts)

Analysis: ParagraphContent._paragraphParentType() (packages/muya/src/block/content/paragraphContent/index.ts) walks up to the nearest list-item / task-list-item / block-quote ancestor, but the list and block-quote Backspace/Enter handlers then treat the paragraph's grandparent as that container. With a footnote in between (list-item > footnote > paragraph), Backspace appends a block into the list item's first paragraph, producing an op that ot-json1 rejects on the next state flush; Enter inserts a list-item into the list-item.

Reproduced in the built desktop app (Playwright + Electron) and in real Chrome against the muya e2e host.

Operating System

macOS

MarkText Version

develop @ a351c50 (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