Collapsing empty nodes on delete

For a reason, I’m creating a nested list structure using something like:

Summary
  • bulletList
    • listItem
    • listItem
    • bulletList
      • listItem
      • listItem

as opposed to

  • bulletList
    • listItem
    • listItem
    • listItem
      • bulletList
        • listItem
        • listItem

I’ve put up an example glitch on https://glitch.com/~judicious-rayon

If I select a range that includes a nested subtree (see example) and either cut or delete it, Prosemirror keeps the nested nodes around, rather than collapsing the slice.

I would expect this if defining were true, but this is not the case here. Am I missing something?

Kind of similar to Defining a container node, that gets removed when empty?, but that looks more like ContentMatch filling the node’s content based on the schema. Here, I’m asking more about the behaviour on doing a replace with an empty slice.

It would be useful to know what range you are deleting and what behavior you expected, precisely.

Selecting and deleting

image

produces

selection-1

so, removing a bulletItem + bulletList containing 2 children. We retain the second bulletList and its child, and empty that. Instead, I would have expected it to look like:

selection-2

where we empty the first bulletItem node and remove the rest.

User intent aside, is this what we expect from Prosemirror out of the box? I guess I’m not entirely across how the replace flow works, so getting an understanding would be amazing. :slight_smile:

That was not intentional behavior. I’ve fixed the bug in this patch.