In Firefox 62.0.3, I can't select the last word of a paragraph, then use 'createLink' to wrap that word in an anchor tag. (You can reproduce this in the demo.) It works when using just document.execCommand(), so I suspected it had to do with the createLink-patch in the core plugin.
Turns out it is a bug in Selection():
- Firefox's document.getSelection() returns a selection with anchorNode set to a #text node containing the word and focusNode set to the parent
node (and focusOffset set so that the selection ends after the #text node child (= the anchorNode).
- Later in the code, the isBefore() helper function is used which does not take into account that child nodes of N come after N in the document, i.e. Selection incorrectly assumes the selection is backwards.
- Finally, creating a new Range and calling setEnd() with the incorrectly swapped start and end results in a collapsed range as per https://developer.mozilla.org/en-US/docs/Web/API/Range/setEnd.
I suggest fixing this by checking isBefore() and Node.contains() in Selection() to prevent wrongly inverting the range. I'll prepare a pull request containing this fix.
In Firefox 62.0.3, I can't select the last word of a paragraph, then use 'createLink' to wrap that word in an anchor tag. (You can reproduce this in the demo.) It works when using just document.execCommand(), so I suspected it had to do with the createLink-patch in the core plugin.
Turns out it is a bug in Selection():
node (and focusOffset set so that the selection ends after the #text node child (= the anchorNode).
I suggest fixing this by checking isBefore() and Node.contains() in Selection() to prevent wrongly inverting the range. I'll prepare a pull request containing this fix.