The inserted slice when splitting block nodes

Hi

I have a question about the splitting of block nodes, for example paragraphs. So what happens is when you split a paragraph is a ReplaceStep is created with two empty paragraph nodes, inserted at the position where the paragraph was split.

The fact that there are indeed two empty created paragraphs is to me confusing. I can understand one empty paragraph which was just inserted but what’s the other paragraph for? If I add attributes to it, those are discarded so it seems it’s not even directly used. What’s the explanation for this behavior?

See openStart/openEnd. What’s being inserted is just the close token from the first paragraph, and the open token from the second.

Ah, yeah. I can see now that the slice has a size of 2 with openStart and openEnd greater than zero while the fragment still has a size of 4. So being open, the node gets joined with an adjacent node of the same type. Or well here the first paragraph closes the old paragraph, whereas the second opens a new one which is merged with the old closing tag.

Okay, that seems discernible enough to detect from a transaction. However, knowing whether a transaction merges paragraphs seems not very trivial either. I guess you just have to check whether the range spans the ending tag and the opening tag of two paragraphs with x deleted content in-between them. Only way I can come up with is using nodesBetween and doing some tricky range checking to see if the deletion includes the nodeEnd (pos + nodeSize) of a block node and somewhere down the line, a node start of a similar node which would collapse into one.

Or maybe you can just take the parent node of them both and compare the children between the start and the end of the deletion to see how many nodes were in fact changed. Maybe that’s smarter considering a slice could also replace the deleted nodes making the whole deletion range checking pointless.