Squire icon indicating copy to clipboard operation
Squire copied to clipboard

fixCursor inserts BR tags in non empty blocks

Open Discolai opened this issue 1 year ago • 0 comments

Reproduction steps:

  1. Call editor.setHTML("<div>Some text</div>")
  2. Subsequent getHTML calls 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))
    ) {

Discolai avatar Jan 13 '25 11:01 Discolai