So additional info on the replacement behaviour, it seems to be fine in practice. As a result of the split paragraph operation, the cursor is always collapsed adjacent to the start of the new paragraph, picking up the style of the new paragraph it's within.

If you wanted a simple safeguard "just in case", you could simply check that the cursor is currently collapsed (cursor.getSelectedRange().collapsed === true) before doing anything. To re-iterate though, the existing code works ok from my brief testing.