mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -05:00
Ensure moving boundaries up tree never passes root
This commit is contained in:
parent
3a17d3793b
commit
9596f4ecf8
6 changed files with 24 additions and 16 deletions
|
@ -865,7 +865,8 @@ var deleteContentsOfRange = function ( range, root ) {
|
||||||
|
|
||||||
// Move boundaries up as much as possible without exiting block,
|
// Move boundaries up as much as possible without exiting block,
|
||||||
// to reduce need to split.
|
// to reduce need to split.
|
||||||
moveRangeBoundariesUpTree( range, startBlock, endBlock );
|
moveRangeBoundariesDownTree( range );
|
||||||
|
moveRangeBoundariesUpTree( range, startBlock, endBlock, root );
|
||||||
|
|
||||||
// Remove selected range
|
// Remove selected range
|
||||||
frag = extractContentsOfRange( range, null, root );
|
frag = extractContentsOfRange( range, null, root );
|
||||||
|
@ -1109,7 +1110,7 @@ var moveRangeBoundariesDownTree = function ( range ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var moveRangeBoundariesUpTree = function ( range, startMax, endMax ) {
|
var moveRangeBoundariesUpTree = function ( range, startMax, endMax, root ) {
|
||||||
var startContainer = range.startContainer;
|
var startContainer = range.startContainer;
|
||||||
var startOffset = range.startOffset;
|
var startOffset = range.startOffset;
|
||||||
var endContainer = range.endContainer;
|
var endContainer = range.endContainer;
|
||||||
|
@ -1124,7 +1125,9 @@ var moveRangeBoundariesUpTree = function ( range, startMax, endMax ) {
|
||||||
endMax = startMax;
|
endMax = startMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( startContainer !== startMax && !startOffset ) {
|
while ( !startOffset &&
|
||||||
|
startContainer !== startMax &&
|
||||||
|
startContainer !== root ) {
|
||||||
parent = startContainer.parentNode;
|
parent = startContainer.parentNode;
|
||||||
startOffset = indexOf.call( parent.childNodes, startContainer );
|
startOffset = indexOf.call( parent.childNodes, startContainer );
|
||||||
startContainer = parent;
|
startContainer = parent;
|
||||||
|
@ -1139,6 +1142,7 @@ var moveRangeBoundariesUpTree = function ( range, startMax, endMax ) {
|
||||||
maySkipBR = false;
|
maySkipBR = false;
|
||||||
}
|
}
|
||||||
if ( endContainer === endMax ||
|
if ( endContainer === endMax ||
|
||||||
|
endContainer === root ||
|
||||||
endOffset !== getLength( endContainer ) ) {
|
endOffset !== getLength( endContainer ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1637,7 +1641,7 @@ var keyHandlers = {
|
||||||
// delete it ourselves, because the browser won't if it is not
|
// delete it ourselves, because the browser won't if it is not
|
||||||
// inline.
|
// inline.
|
||||||
originalRange = range.cloneRange();
|
originalRange = range.cloneRange();
|
||||||
moveRangeBoundariesUpTree( range, root, root );
|
moveRangeBoundariesUpTree( range, root, root, root );
|
||||||
cursorContainer = range.endContainer;
|
cursorContainer = range.endContainer;
|
||||||
cursorOffset = range.endOffset;
|
cursorOffset = range.endOffset;
|
||||||
if ( cursorContainer.nodeType === ELEMENT_NODE ) {
|
if ( cursorContainer.nodeType === ELEMENT_NODE ) {
|
||||||
|
@ -2233,7 +2237,7 @@ var onCopy = function ( event ) {
|
||||||
// passing the copy root node.
|
// passing the copy root node.
|
||||||
range = range.cloneRange();
|
range = range.cloneRange();
|
||||||
moveRangeBoundariesDownTree( range );
|
moveRangeBoundariesDownTree( range );
|
||||||
moveRangeBoundariesUpTree( range, copyRoot, copyRoot );
|
moveRangeBoundariesUpTree( range, copyRoot, copyRoot, root );
|
||||||
// Extract the contents
|
// Extract the contents
|
||||||
parent = range.commonAncestorContainer;
|
parent = range.commonAncestorContainer;
|
||||||
contents = range.cloneContents();
|
contents = range.cloneContents();
|
||||||
|
@ -3744,7 +3748,7 @@ proto.modifyBlocks = function ( modify, range ) {
|
||||||
expandRangeToBlockBoundaries( range, root );
|
expandRangeToBlockBoundaries( range, root );
|
||||||
|
|
||||||
// 3. Remove range.
|
// 3. Remove range.
|
||||||
moveRangeBoundariesUpTree( range, root, root );
|
moveRangeBoundariesUpTree( range, root, root, root );
|
||||||
frag = extractContentsOfRange( range, root, root );
|
frag = extractContentsOfRange( range, root, root );
|
||||||
|
|
||||||
// 4. Modify tree of fragment and reinsert.
|
// 4. Modify tree of fragment and reinsert.
|
||||||
|
@ -4478,7 +4482,7 @@ proto.removeAllFormatting = function ( range ) {
|
||||||
this.saveUndoState( range );
|
this.saveUndoState( range );
|
||||||
|
|
||||||
// Avoid splitting where we're already at edges.
|
// Avoid splitting where we're already at edges.
|
||||||
moveRangeBoundariesUpTree( range, stopNode, stopNode );
|
moveRangeBoundariesUpTree( range, stopNode, stopNode, root );
|
||||||
|
|
||||||
// Split the selection up to the block, or if whole selection in same
|
// Split the selection up to the block, or if whole selection in same
|
||||||
// block, expand range boundaries to ends of block and split up to root.
|
// block, expand range boundaries to ends of block and split up to root.
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -107,7 +107,7 @@ var onCopy = function ( event ) {
|
||||||
// passing the copy root node.
|
// passing the copy root node.
|
||||||
range = range.cloneRange();
|
range = range.cloneRange();
|
||||||
moveRangeBoundariesDownTree( range );
|
moveRangeBoundariesDownTree( range );
|
||||||
moveRangeBoundariesUpTree( range, copyRoot, copyRoot );
|
moveRangeBoundariesUpTree( range, copyRoot, copyRoot, root );
|
||||||
// Extract the contents
|
// Extract the contents
|
||||||
parent = range.commonAncestorContainer;
|
parent = range.commonAncestorContainer;
|
||||||
contents = range.cloneContents();
|
contents = range.cloneContents();
|
||||||
|
|
|
@ -1301,7 +1301,7 @@ proto.modifyBlocks = function ( modify, range ) {
|
||||||
expandRangeToBlockBoundaries( range, root );
|
expandRangeToBlockBoundaries( range, root );
|
||||||
|
|
||||||
// 3. Remove range.
|
// 3. Remove range.
|
||||||
moveRangeBoundariesUpTree( range, root, root );
|
moveRangeBoundariesUpTree( range, root, root, root );
|
||||||
frag = extractContentsOfRange( range, root, root );
|
frag = extractContentsOfRange( range, root, root );
|
||||||
|
|
||||||
// 4. Modify tree of fragment and reinsert.
|
// 4. Modify tree of fragment and reinsert.
|
||||||
|
@ -2035,7 +2035,7 @@ proto.removeAllFormatting = function ( range ) {
|
||||||
this.saveUndoState( range );
|
this.saveUndoState( range );
|
||||||
|
|
||||||
// Avoid splitting where we're already at edges.
|
// Avoid splitting where we're already at edges.
|
||||||
moveRangeBoundariesUpTree( range, stopNode, stopNode );
|
moveRangeBoundariesUpTree( range, stopNode, stopNode, root );
|
||||||
|
|
||||||
// Split the selection up to the block, or if whole selection in same
|
// Split the selection up to the block, or if whole selection in same
|
||||||
// block, expand range boundaries to ends of block and split up to root.
|
// block, expand range boundaries to ends of block and split up to root.
|
||||||
|
|
|
@ -362,7 +362,7 @@ var keyHandlers = {
|
||||||
// delete it ourselves, because the browser won't if it is not
|
// delete it ourselves, because the browser won't if it is not
|
||||||
// inline.
|
// inline.
|
||||||
originalRange = range.cloneRange();
|
originalRange = range.cloneRange();
|
||||||
moveRangeBoundariesUpTree( range, root, root );
|
moveRangeBoundariesUpTree( range, root, root, root );
|
||||||
cursorContainer = range.endContainer;
|
cursorContainer = range.endContainer;
|
||||||
cursorOffset = range.endOffset;
|
cursorOffset = range.endOffset;
|
||||||
if ( cursorContainer.nodeType === ELEMENT_NODE ) {
|
if ( cursorContainer.nodeType === ELEMENT_NODE ) {
|
||||||
|
|
|
@ -140,7 +140,8 @@ var deleteContentsOfRange = function ( range, root ) {
|
||||||
|
|
||||||
// Move boundaries up as much as possible without exiting block,
|
// Move boundaries up as much as possible without exiting block,
|
||||||
// to reduce need to split.
|
// to reduce need to split.
|
||||||
moveRangeBoundariesUpTree( range, startBlock, endBlock );
|
moveRangeBoundariesDownTree( range );
|
||||||
|
moveRangeBoundariesUpTree( range, startBlock, endBlock, root );
|
||||||
|
|
||||||
// Remove selected range
|
// Remove selected range
|
||||||
frag = extractContentsOfRange( range, null, root );
|
frag = extractContentsOfRange( range, null, root );
|
||||||
|
@ -384,7 +385,7 @@ var moveRangeBoundariesDownTree = function ( range ) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var moveRangeBoundariesUpTree = function ( range, startMax, endMax ) {
|
var moveRangeBoundariesUpTree = function ( range, startMax, endMax, root ) {
|
||||||
var startContainer = range.startContainer;
|
var startContainer = range.startContainer;
|
||||||
var startOffset = range.startOffset;
|
var startOffset = range.startOffset;
|
||||||
var endContainer = range.endContainer;
|
var endContainer = range.endContainer;
|
||||||
|
@ -399,7 +400,9 @@ var moveRangeBoundariesUpTree = function ( range, startMax, endMax ) {
|
||||||
endMax = startMax;
|
endMax = startMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( startContainer !== startMax && !startOffset ) {
|
while ( !startOffset &&
|
||||||
|
startContainer !== startMax &&
|
||||||
|
startContainer !== root ) {
|
||||||
parent = startContainer.parentNode;
|
parent = startContainer.parentNode;
|
||||||
startOffset = indexOf.call( parent.childNodes, startContainer );
|
startOffset = indexOf.call( parent.childNodes, startContainer );
|
||||||
startContainer = parent;
|
startContainer = parent;
|
||||||
|
@ -414,6 +417,7 @@ var moveRangeBoundariesUpTree = function ( range, startMax, endMax ) {
|
||||||
maySkipBR = false;
|
maySkipBR = false;
|
||||||
}
|
}
|
||||||
if ( endContainer === endMax ||
|
if ( endContainer === endMax ||
|
||||||
|
endContainer === root ||
|
||||||
endOffset !== getLength( endContainer ) ) {
|
endOffset !== getLength( endContainer ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue