With Rangy, Even Though I Extend The Range By Setstartbefore Method, Range.cansurroundcontents Method Still Returns False
I have the following html:
Morbi quis augue vitae quam pharetra| varius at at| urna.
The selection is marked with | characters. AlsoSolution 1:
I think the problem is that anchorNode
is the text node within the link rather than the link itself, so the selection starts within the link rather than before it. Moving the start of the range before the link should fix it. Also, there is no need to call refresh()
on the selection unless something other than Rangy has modified it, although that won't be causing any problems here.
Revised jsFiddle: http://jsfiddle.net/LTwkZ/2/
Code:
$('body').on('mouseup', '[contenteditable]', function() {
var block = this,
sel = rangy.getSelection(),
range = sel.getRangeAt(0);
if (sel.anchorNode.parentNode !== block) {
range.setStartBefore(sel.anchorNode.parentNode);
sel.setSingleRange(range, false);
}
});
Post a Comment for "With Rangy, Even Though I Extend The Range By Setstartbefore Method, Range.cansurroundcontents Method Still Returns False"