Squire
Squire copied to clipboard
fixCursor inserts BR tags in non empty blocks
Reproduction steps:
- Call
editor.setHTML("<div>Some text</div>") - Subsequent
getHTMLcalls will then return<div>Some text<br></div>
This causes issues in our revision system, since it picks up changes in the html without any user input.
I believe I have pinpointed it to the fixCursor function, which makes sure all elements are selectable. It does this by appending a BR to all block elements. This should only be necessary for empty block elements.
https://github.com/fastmail/Squire/blob/cbd8881e78c2af0305a0b6a06cdff16c0c0b05ed/source/node/MergeSplit.ts#L40C4-L43C8
So i suggest the following change to make sure non-empty blocks are left unchanged
} else if (
(node instanceof Element || node instanceof DocumentFragment) &&
(!node.querySelector('BR') && !node.textContent))
) {