I am trying to implement the following user action:
-
User selects multiple nodes:
Text before
- A
- B
- C
Text between
- D
- E
- F
Text after
-
User clicks the
bullet button
-
Output:
- Text before
- A
- B
- C
- Text between
- D
- E
- F
- Text after
The closest I have come to a solution is the following:
const { $from, $to, from, to } = state.selection;
const listItems = [];
state.doc.node.nodesBetween(from, to, node => {
//Check if the node is a paragraph or list_item
//Grab node's fragment and generate a new list_item node
//Add new node to listItems
return false;
});
//Replace selection with new list node
dispatch(state.tr.replaceSelection(from, to, nodeType.create(null, listItems)).scrollIntoView());
return true;
I have the following questions:
- What am I not understanding about ProseMirror’s data structure?
- Is looping through each node in the selection the correct approach?
- Should I try transforming the
TextSelection
itself?