0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Always restore range to textnodes.

When restoring a range from a bookmark, always call range.moveBoundariesDownTree
to anchor it to the nearest text node. If you call setSelection with a range not
anchored inside a textnode, Opera may incorrectly set the selection.
This commit is contained in:
Neil Jenkins 2012-06-19 14:35:44 +10:00
parent ffd6edbaef
commit 819ddb296e
2 changed files with 8 additions and 5 deletions

File diff suppressed because one or more lines are too long

View file

@ -325,7 +325,8 @@
if ( start && end ) { if ( start && end ) {
var startContainer = start.parentNode, var startContainer = start.parentNode,
endContainer = end.parentNode; endContainer = end.parentNode,
collapsed;
var _range = { var _range = {
startContainer: startContainer, startContainer: startContainer,
@ -352,9 +353,11 @@
} }
range.setStart( _range.startContainer, _range.startOffset ); range.setStart( _range.startContainer, _range.startOffset );
range.setEnd( _range.endContainer, _range.endOffset ); range.setEnd( _range.endContainer, _range.endOffset );
collapsed = range.collapsed;
if ( !range.collapsed ) {
range.moveBoundariesDownTree(); range.moveBoundariesDownTree();
if ( collapsed ) {
range.collapse( true );
} }
} }
return range; return range;