Cellselection + setBlockType

I’m trying to figure out a bug in which when I select multiple cells in a ProseMirror Table and trigger the setBlockType command, only the last cell gets formatted. For example if I select 2 cells like this


the resulting selection is 2 CellSelections however when calling setBlockType the first cell fails to get a header. I’m not sure how to debug this as it doesn’t seem like we’re doing much other than just calling the command. Any help would be appreciated!


Something I discovered is that if I hijack the command and call this instead

      const { from, to } = state.selection;
      dispatch(state.tr.setBlockType(from - 3, to, nodeType, attrs));

the first cell gets the header applied

Edit 2

It seems like when iterating over nodes between here prosemirror-transform/structure.js at c3bbb16560f2b0f1df3a79a3237ffa051bf747a7 · ProseMirror/prosemirror-transform · GitHub the paragraph node in the first cell never gets included in the iteration. I wonder if there’s something funky going on with the indexing of CellSelections

Edit 3

Further playing around reveals that the blockType only gets applied to the last cell in a selection

Edit 4


Realized that setBlockType worked on the to and from on the CellSelection instead of the ranges which wasn’t consistent with a function like prosemirror-commands/commands.js at 3dbb05b63b39d1773040cda41e84b60a085ebd43 · ProseMirror/prosemirror-commands · GitHub. So instead I mapped over the ranges of the cell selection and called setBlockType on each range.