Truncate transactions that add new children

Hi again! I’m trying to get the following behavior but I’m struggling a bit with the right implementation. In my case, a single page has multiple ProseMirror instances activated when clicked (I can’t make it a single document because it’s not only text and I need lots of interactivity already provided by the UI library).

So, when a user deletes a block of text that’s already empty, I can check the doc’s size and delete the entry in the database. But what I couldn’t figure out is when a user inserts new children into the doc (could be one, in case of the Enter key, or many, in case of a paste), how to update the transaction to only keep the changes that affect the current block of text and handle the rest on my own (create their own entries in the database and so on).

dispatchTransaction seems to be the way to go, but how do I “truncate” the transaction?






The transaction would be [insert d, insert efgh] but I want to make it [insert d] only and handle the [insert efgh] on my own.

Thank you!


Using deleteRange seems to be doing the trick, but I’m not sure how to get the whole range?

let newState = viewRef.state.apply(transaction)
if (newState.doc.childCount > 1) {
	const tr =
		newState.doc.firstChild.nodeSize + newState.doc.lastChild.nodeSize

	newState = newState.apply(tr)

Update 2

It seems that using newState.doc.content.size is enough to get the range I wanted to delete.