fastmail / Squire

The rich text editor for arbitrary HTML.
MIT License
4.75k stars 406 forks source link

Cursor position bug after link('a' element) paste in Firefox #451

Closed SergeyMosin closed 7 months ago

SergeyMosin commented 9 months ago

Cursor jumps to the beginning of a line (see the video) when an 'a' element is pasted after some text in Firefox (Chrome is unaffected)

It looks like Firefox does not like the cursor/range being set to between the end of a element and the end of parent block ( ex: <div>some text: <a>some link</a>|</div> ) in the moveRangeBoundaryOutOf function https://github.com/fastmail/Squire/blob/8bee51683b723e000f477009ed4337716a7b80ba/source/range/Boundaries.ts#L163

However if the fixCursor function is called on line 174 everything works

        if (clone.endContainer === parent) {
            fixCursor(parent) // << ADD THIS ON LINE 174
            range.setStart(clone.endContainer, clone.endOffset);
            range.setEnd(clone.endContainer, clone.endOffset);
        }

The parent looks like this now <div>some text: <a>some link</a>|<br></div> before the range is set and the cursor behaves normally in Firefox

firefox-link-paste-bug.webm