mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Restore range more accurately from bookmark
This commit is contained in:
parent
ed44d72ca7
commit
d9122222b2
3 changed files with 30 additions and 6 deletions
|
@ -2819,9 +2819,21 @@ proto._getRangeAndRemoveBookmark = function ( range ) {
|
|||
range.setEnd( _range.endContainer, _range.endOffset );
|
||||
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 ) {
|
||||
range.collapse( true );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return range || null;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -613,9 +613,21 @@ proto._getRangeAndRemoveBookmark = function ( range ) {
|
|||
range.setEnd( _range.endContainer, _range.endOffset );
|
||||
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 ) {
|
||||
range.collapse( true );
|
||||
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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return range || null;
|
||||
|
|
Loading…
Reference in a new issue