0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-01-08 16:00:06 -05:00

Restore range more accurately from bookmark

This commit is contained in:
Neil Jenkins 2016-03-30 16:39:04 +11:00
parent ed44d72ca7
commit d9122222b2
3 changed files with 30 additions and 6 deletions

View file

@ -2819,11 +2819,23 @@ proto._getRangeAndRemoveBookmark = function ( range ) {
range.setEnd( _range.endContainer, _range.endOffset ); range.setEnd( _range.endContainer, _range.endOffset );
collapsed = range.collapsed; collapsed = range.collapsed;
moveRangeBoundariesDownTree( range ); // If we didn't split a text node, we should move into any adjacent
// text node to current selection point
if ( collapsed ) { if ( collapsed ) {
startContainer = range.startContainer;
if ( startContainer.nodeType === TEXT_NODE ) {
endContainer = startContainer.childNodes[ range.startOffset ];
if ( !endContainer || endContainer.nodeType !== TEXT_NODE ) {
endContainer =
startContainer.childNodes[ range.startOffset - 1 ];
}
if ( endContainer && endContainer.nodeType === TEXT_NODE ) {
range.setStart( endContainer, 0 );
range.collapse( true ); range.collapse( true );
} }
} }
}
}
return range || null; return range || null;
}; };

File diff suppressed because one or more lines are too long

View file

@ -613,11 +613,23 @@ proto._getRangeAndRemoveBookmark = function ( range ) {
range.setEnd( _range.endContainer, _range.endOffset ); range.setEnd( _range.endContainer, _range.endOffset );
collapsed = range.collapsed; collapsed = range.collapsed;
moveRangeBoundariesDownTree( range ); // If we didn't split a text node, we should move into any adjacent
// text node to current selection point
if ( collapsed ) { if ( collapsed ) {
startContainer = range.startContainer;
if ( startContainer.nodeType === TEXT_NODE ) {
endContainer = startContainer.childNodes[ range.startOffset ];
if ( !endContainer || endContainer.nodeType !== TEXT_NODE ) {
endContainer =
startContainer.childNodes[ range.startOffset - 1 ];
}
if ( endContainer && endContainer.nodeType === TEXT_NODE ) {
range.setStart( endContainer, 0 );
range.collapse( true ); range.collapse( true );
} }
} }
}
}
return range || null; return range || null;
}; };