Skip to content

[Bug] Tab on a list item appends it to the previous item's sublist even when that sublist holds the other item kind #5349

Closed

Description

@Jocs

Description

Pressing Tab on a list item nests it under the previous item. If the previous item already ends with a sublist, the item is appended to that sublist even when the sublist holds the other item kind: a task item goes into a bullet list, or a plain item goes into a task list. The editor state becomes invalid (a bullet-list / order-list may only hold list-item, a task-list only task-list-item), and later edits keep adding items of the wrong kind to that list. Reopening the document gives a different structure than the one the editor had.

This is the indent direction of #5341 (fixed for Shift+Tab by #5348). No error is thrown.

Steps to Reproduce

  1. Open a document with:
    - [ ] a
      - b
    - [ ] c
  2. Click at the end of c and press Tab.
  3. Type z, press Enter, type n.

The reverse also reproduces it:

- a
  - [ ] b
- c

(Tab on c puts a plain item into the task list; the same happens with an ordered outer list 1. a / - [ ] b / 2. c.)

Expected Behavior

The indented item keeps its kind (and checked state). When the previous item's last sublist holds the same kind, the item is appended to it as today; when it holds the other kind, the item goes into a new list of its own kind, placed after that sublist inside the previous item:

before Tab:  task-list( task-list-item( "a", bullet-list( list-item("b") ) ), task-list-item("c") )
after Tab:   task-list( task-list-item( "a", bullet-list( list-item("b") ), task-list( task-list-item("c") ) ) )

That is the structure muya's parser builds when the saved markdown is reopened, so the document stays the same across a reopen, the same rule as #5341.

Actual Behavior

Measured on develop in real Chrome (muya e2e host) and in the built desktop app:

Document State after Tab After reopening the saved markdown
- [ ] a / - b / - [ ] c a{ bullet-list{ b, task-list-item c } } a{ bullet-list{ b }, task-list{ c } }
- a / - [ ] b / - c a{ task-list{ b, list-item c } } a{ task-list{ b }, bullet-list{ c } }
1. a / - [ ] b / 2. c a{ task-list{ b, list-item c } } a{ task-list{ b }, bullet-list{ c } }
- [ ] a / - b / - [x] c a{ bullet-list{ b, task-list-item [x]c } } a{ bullet-list{ b }, task-list{ [x]c } }

After step 3 the new n item is also added to the wrong list. In the desktop app the rendered DOM shows mu-bullet-list[mu-list-item:b, mu-task-list-item:c] (and mu-task-list[mu-task-list-item:b, mu-list-item:c] for the reverse case). Same-kind sublists and items without a sublist indent correctly, and undo restores the document in every case.

Screenshots / Logs

Analysis: ParagraphContent._indentListItem() (packages/muya/src/block/content/paragraphContent/index.ts) takes prevListItem.lastChild and, if it is any ul/ol, appends the cloned item to it without checking that the list holds the item's kind; it only creates a new list (of the item's own list type) when the previous item has no trailing list. Found while working on #5345.

Operating System

macOS

MarkText Version

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