mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
parent
d225f384b7
commit
7ecf75f246
3 changed files with 35 additions and 17 deletions
|
@ -1098,7 +1098,7 @@ var getEndBlockOfRange = function ( range, root ) {
|
|||
block = container;
|
||||
} else {
|
||||
block = getNodeAfter( container, range.endOffset );
|
||||
if ( !block ) {
|
||||
if ( !block || !isOrContains( root, block ) ) {
|
||||
block = root;
|
||||
while ( child = block.lastChild ) {
|
||||
block = child;
|
||||
|
@ -1120,8 +1120,9 @@ var contentWalker = new TreeWalker( null,
|
|||
);
|
||||
|
||||
var rangeDoesStartAtBlockBoundary = function ( range, root ) {
|
||||
var startContainer = range.startContainer,
|
||||
startOffset = range.startOffset;
|
||||
var startContainer = range.startContainer;
|
||||
var startOffset = range.startOffset;
|
||||
var nodeAfterCursor;
|
||||
|
||||
// If in the middle or end of a text node, we're not at the boundary.
|
||||
contentWalker.root = null;
|
||||
|
@ -1129,16 +1130,24 @@ var rangeDoesStartAtBlockBoundary = function ( range, root ) {
|
|||
if ( startOffset ) {
|
||||
return false;
|
||||
}
|
||||
contentWalker.currentNode = startContainer;
|
||||
nodeAfterCursor = startContainer;
|
||||
} else {
|
||||
contentWalker.currentNode = getNodeAfter( startContainer, startOffset );
|
||||
|
||||
if ( !contentWalker.currentNode ) {
|
||||
contentWalker.currentNode = startContainer;
|
||||
nodeAfterCursor = getNodeAfter( startContainer, startOffset );
|
||||
if ( nodeAfterCursor && !isOrContains( root, nodeAfterCursor ) ) {
|
||||
nodeAfterCursor = null;
|
||||
}
|
||||
// The cursor was right at the end of the document
|
||||
if ( !nodeAfterCursor ) {
|
||||
nodeAfterCursor = getNodeBefore( startContainer, startOffset );
|
||||
if ( nodeAfterCursor.nodeType === TEXT_NODE &&
|
||||
nodeAfterCursor.length ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, look for any previous content in the same block.
|
||||
contentWalker.currentNode = nodeAfterCursor;
|
||||
contentWalker.root = getStartBlockOfRange( range, root );
|
||||
|
||||
return !contentWalker.previousNode();
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -438,7 +438,7 @@ var getEndBlockOfRange = function ( range, root ) {
|
|||
block = container;
|
||||
} else {
|
||||
block = getNodeAfter( container, range.endOffset );
|
||||
if ( !block ) {
|
||||
if ( !block || !isOrContains( root, block ) ) {
|
||||
block = root;
|
||||
while ( child = block.lastChild ) {
|
||||
block = child;
|
||||
|
@ -460,8 +460,9 @@ var contentWalker = new TreeWalker( null,
|
|||
);
|
||||
|
||||
var rangeDoesStartAtBlockBoundary = function ( range, root ) {
|
||||
var startContainer = range.startContainer,
|
||||
startOffset = range.startOffset;
|
||||
var startContainer = range.startContainer;
|
||||
var startOffset = range.startOffset;
|
||||
var nodeAfterCursor;
|
||||
|
||||
// If in the middle or end of a text node, we're not at the boundary.
|
||||
contentWalker.root = null;
|
||||
|
@ -469,16 +470,24 @@ var rangeDoesStartAtBlockBoundary = function ( range, root ) {
|
|||
if ( startOffset ) {
|
||||
return false;
|
||||
}
|
||||
contentWalker.currentNode = startContainer;
|
||||
nodeAfterCursor = startContainer;
|
||||
} else {
|
||||
contentWalker.currentNode = getNodeAfter( startContainer, startOffset );
|
||||
|
||||
if ( !contentWalker.currentNode ) {
|
||||
contentWalker.currentNode = startContainer;
|
||||
nodeAfterCursor = getNodeAfter( startContainer, startOffset );
|
||||
if ( nodeAfterCursor && !isOrContains( root, nodeAfterCursor ) ) {
|
||||
nodeAfterCursor = null;
|
||||
}
|
||||
// The cursor was right at the end of the document
|
||||
if ( !nodeAfterCursor ) {
|
||||
nodeAfterCursor = getNodeBefore( startContainer, startOffset );
|
||||
if ( nodeAfterCursor.nodeType === TEXT_NODE &&
|
||||
nodeAfterCursor.length ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, look for any previous content in the same block.
|
||||
contentWalker.currentNode = nodeAfterCursor;
|
||||
contentWalker.root = getStartBlockOfRange( range, root );
|
||||
|
||||
return !contentWalker.previousNode();
|
||||
|
|
Loading…
Reference in a new issue