I know that
markRange has previously been replaced with Decorations, and I also know that commenting cross node has been discussed a fair bit on here and there are questions re: their validity in a document model. However, comments definitely form part of our document model and as such I’ve spent the last couple of days reimplementing the logic for markRange.
This has meant creating a separate model that stores the start and end of comments and maps all those positions through each transaction before appending a transaction that handles
storedMarks and removing them. I also use Decorations for showing the start / end of comments that span a few nodes. Undo and copy / paste were pretty hairy areas to sort out (going through the added slice, scanning for marks, rebuilding the model etc.) but I’ve sort of got it working. I can’t help but feel that I’m definitely fighting against the API a bit here and wondered if there were a preferred way to go about this?
The approach I’ve got for commenting works (until I find an edge case that it doesn’t work for) but it doesn’t feel efficient and it certainly doesn’t feel like I’m using ProseMirror in the way it was intended.
For example, as mentioned above, in order to cleanly handle undo / paste operations I need to find all the marks in the edited range and rebuild the comment model from their (giving them a new id). To do this I’ve repurposed the code from
tr.removeMark to find all the marks and go from there. As finding mark positions isn’t part of the API even though the logic is present in the library I wonder if either there is a plan to expose tools to handle this sort of plugin or otherwise to handle marks that span multiple nodes more broadly without a plugin?