and then press enter when my cursor is at the end of Heading 3, a new paragraph line is generated, just as expected.
However, if I copy the whole thing, and paste it when my cursor is at the end of Heading 3 (without first pressing enter), an extra h3 line appears after paste, while the expected behaviour was for the cursor to either be at the end of Heading 3 without an extra line after that, or for the extra line to be of paragraph type.
This only happens when you do ctrl/cmd-a in the editor before copying, right? When I copy from this forum message, or drag across the entire document with the pointer and then copy, this doesn’t occur (there’s no blank line at the end).
When copying after select-all, you get a slice that isn’t ‘open’ at its end—i.e. the nodes inside it are considered entire, closed nodes, not pieces that have to be joined to other nodes. That is causing the replace algorithm to cut the h3 node that holds the selection in two, leaving the empty selection node at the end.
This is somewhat arbitrary, but doesn’t seem like a big enough problem to warrant special handling.
I resolved this by adding a br tag rule to paragraph and in getAttrs on both paragraph and hard break opposite checks on the parent node name. This limits breaks to being inside PARAGRAPH and SPAN, otherwise a paragraph gets created.