Functional of lists

Hi

I had some experience with ProseMirror but I understood it badly. Now I try to understand it better and I’m already getting it (btw TypeScript types help a lot in this). I’d like to try to create own functional around some lists (I tried to see source code of the “prosemirror-schema-list” but I didn’t understand it :sweat_smile:).
And this is my case:

My schema has such types:

  1. The list’s type (“ul” for example)
  2. The list item (just “li”)

I want to realize method of wrapping the selection to a list type. First of all, I want to understand how to wrap my selected nodes. Right now I don’t think about the behavior when I select already a created list and I don’t think about the “auto joining”. I just want to wrap some text nodes in list.

And I had following thoughts:

  1. Create “Fragment” and fill it
  2. Create the instance of list’s type (“ul” for example) and fill it

In both cases I thought about that to get all nodes in the selection by “view.state.doc.nodesBetween” method and check every node, change it and push in my result. After It just replace the selection on my result.

I will be glad if someone pushes me on the right path. I want to know how to think correctly in such cases. @marijn I’ve already taken up a lot of your time but probably this question may only be answered by you. Thanks for ProseMirror!

Pretty close, I think. Here’s how prosemirror-schema-list does it: prosemirror-schema-list/schema-list.ts at 757e45bc8b93e966c8b74a6748e1ac32859adc45 · ProseMirror/prosemirror-schema-list · GitHub

I saw it but I didn’t understand it :frowning: