Hi,
so as I was using findDiffEnd
in my plugin’s appendTransaction I did not fully understand which value to use from oldState.doc.content.findDiffEnd(newState.doc.content)
as the to
value for nodesBetween
to only iterate over the changed content: newState.doc.nodesBetween(from, to ...
I was using the a
value which is the end in the oldState.doc
whereas b
would be in the newState. Silly mistake but which was made a lot harder to detect as the appendTransaction would function fine when the changes weren’t done to the end of the doc. And when they where made eg I deleted the last paragraph, this error was thrown:
fragment.js:28 Uncaught TypeError: Cannot read properties of undefined (reading 'nodeSize')
at Fragment.nodesBetween (fragment.js:28:1)
at Node.nodesBetween (node.js:84:1)
at Plugin.appendTransaction (persist.ts:22:1)
at EditorState.applyTransaction (state.js:128:1)
at EditorView.dispatchTransaction (subscribeToTransactions.ts:15:1)
at EditorView.dispatch (index.js:399:1)
at <anonymous>:3:15
at <anonymous>:5:3
Which doesn’t say a whole lot what is going on. First I thought it was about duplicate imports but it simply is because I’m trying to iterate doc beyond its content size.
So could it be possible to have this method throw an error if the to
is over this.content.length
with a message like nodesBetween: 'to' over fragment's size
or something?
EDIT: actually there were two bugs, the other with the findDiffEnd
and the other using tr.doc.nodesBetween(fromA, toA ...
instead of oldState.doc.nodesBetween(from, toA ...
inside filterTransaction.