Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixCursor inserts BR tags in non empty blocks #476

Open
Discolai opened this issue Jan 13, 2025 · 0 comments
Open

fixCursor inserts BR tags in non empty blocks #476

Discolai opened this issue Jan 13, 2025 · 0 comments

Comments

@Discolai
Copy link

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))
    ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant