Mix bullet and ordered list

Hi,

I am implementing a menu that should allow me to swap easily between bullet or ordered list. I’ve managed to get something that works unless we start mixing types of list:

  • here is the starting point, an ordered list followed by a bullet list

image

  • when I apply a bullet list, it will incorrectly nest the list. Instead it should have removed the existing level (using liftListItem) then rewrapped them with the correct type (using wrapInList). The lift part is probably incorrect.

image

The issue is that I didn’t yet find a way to iterate on the selection to detect all types of list it may contain. I am doing const innerNode = state.selection.$from.node(1);, which will correctly get the parent “bullet” or “ordered” list if there is only one type of list. If there is a mix in the selection, it will get only the 1st list.

selection.ranges gives only one range, while I would have expected a list I could iterate on.

What features should I explore to bypass this issue? I probably miss something about selections and nodes.

I am also using liftListItem which is probably too granular, instead I want to lift all items of all the selected lists before applying the new type. I think I can even reproduce the issue when creating two lists of the same type one after the other.

You can iterate through a NodeRange using its parent, startIndex, and endIndex properties (i.e. calling parent.childAt(...) on the covered indices).

1 Like