Firefox issue: sel.addRange(range, true) may fail depending on where the focus is

87 views
Skip to first unread message

Louis-Dominique Dubeau

unread,
Sep 27, 2013, 8:36:22 AM9/27/13
to ra...@googlegroups.com

This is a problem with Firefox (24), not with rangy but I thought people using rangy might like to know (so as to avoid the few hours I spent tracking down this bug). The bug has been reported here:

https://bugzilla.mozilla.org/show_bug.cgi?id=921444

This bug would manifest while using rangy if you ever use sel.addRange(range, true) to add a range "backwards". That's something I do in my software when a user actually selects text backwards. (I can't let the browser handle it itself because contenteditable is pretty much a broken feature, the way browsers handle input methods, etc.) When addRange is called to add a range backwards and there is an extend() method available on selections, then rangy uses the extend() method, which may trigger the issue. And actually, if you do use extend() yourself in your own code, outside of rangy, (which I do) then you can get that error there too.

This problem happens if at the time extend() is called the element which contains the selection to be extended is not the same as the element which is currently focused. On Firefox, for some reason, if the focus is in element X, and JS code sets the selection to be in element Y's text and Y is focusable, then the focus remains in X. On Chrome, setting the selection to Y's text also focuses Y.

The workaround is to manually move the focus before extending. I'm not reporting it as a rangy issue since it is not a rangy bug.

Frank Arensmeier

unread,
Sep 27, 2013, 1:58:35 PM9/27/13
to ra...@googlegroups.com
Thanks for the heads up. 
/frank
--
You received this message because you are subscribed to the Google Groups "rangy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rangy+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tim Down

unread,
Sep 29, 2013, 11:11:14 AM9/29/13
to ra...@googlegroups.com
Interesting. Thanks for posting this.

Tim
Reply all
Reply to author
Forward
0 new messages