@rich I rewrote/refactored the way tracked changes are applied. Instead of appending a transaction through a plugin, I now directly replace the original transaction with a modified one as described here. Advantages so far are:
- about 20% fewer lines of code
- basic insertions (the majority of operations) are now just one condensed
ReplaceStep
rather than aReplaceStep
and anAddMarkStep
. - deletions are directly replaced with
AddMarkStep
s instead of first deleted, then readded and then marked - undo/redo events work as before tracked changes
- one odd bug seems to either show less frequently or have gone away entirely.
Disadvantages are likely that:
- Doing a replacement of the transaction can only be done in the editor’s
dispatchTransaction
method, so it’s not as well connected to the rest of ProseMirror and it probably only works because I only do this for one component. - I cannot really see how I should be copying the meta object from the original tr to the replacement one or whether this could lead to any issues. Currently I just do
newTr.meta = tr.meta
which likely is completely forbidden. The test seem to run though. - There are some oddities about the selection. I have to use the
setSelection
method if the new tr’s selection is not moving in the same direction is it is in the originaltr
. I seem to have covered most/all normal cases, but very likely there will be edge cases where the selection still behaves strangely.
PS: I have been wondering why assigning the meta like described does not lead to errors. It’s probably because I use the original tr
in just about all cases where prosemirror-internal meta information is being used: tr
s without steps are not being replaced. Same goes for tr
s that come out of the collab or history module and a bunch of others for which I have set specific meta-data. The only ones that I am aware of that do have meta data that are being exchanged are those for whom I added meta data like 'inputType'=== 'deleteBackward'
and similar that do not contain any position or step data.