mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Add guard for null nodes in insertTreeFragmentIntoRange
This commit is contained in:
parent
66c0b20702
commit
44a2b5c7a8
4 changed files with 12 additions and 16 deletions
|
@ -210,7 +210,7 @@ function isContainer ( node ) {
|
|||
}
|
||||
|
||||
function getBlockWalker ( node, root ) {
|
||||
var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock, false );
|
||||
var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock );
|
||||
walker.currentNode = node;
|
||||
return walker;
|
||||
}
|
||||
|
@ -914,13 +914,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
|
|||
// merge containers at the edges.
|
||||
next = nodeBeforeSplit.nextSibling;
|
||||
node = getPreviousBlock( next, root );
|
||||
if ( !/\S/.test( node.textContent ) ) {
|
||||
if ( node && !/\S/.test( node.textContent ) ) {
|
||||
do {
|
||||
parent = node.parentNode;
|
||||
parent.removeChild( node );
|
||||
node = parent;
|
||||
} while ( parent && !parent.lastChild &&
|
||||
parent.nodeName !== 'BODY' );
|
||||
} while ( node && !node.lastChild && node !== root );
|
||||
}
|
||||
if ( !nodeBeforeSplit.parentNode ) {
|
||||
nodeBeforeSplit = next.previousSibling;
|
||||
|
@ -938,13 +937,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
|
|||
prev = nodeAfterSplit.previousSibling;
|
||||
node = isBlock( nodeAfterSplit ) ?
|
||||
nodeAfterSplit : getNextBlock( nodeAfterSplit, root );
|
||||
if ( !/\S/.test( node.textContent ) ) {
|
||||
if ( node && !/\S/.test( node.textContent ) ) {
|
||||
do {
|
||||
parent = node.parentNode;
|
||||
parent.removeChild( node );
|
||||
node = parent;
|
||||
} while ( parent && !parent.lastChild &&
|
||||
parent.nodeName !== 'BODY' );
|
||||
} while ( node && !node.lastChild && node !== root );
|
||||
}
|
||||
if ( !nodeAfterSplit.parentNode ) {
|
||||
nodeAfterSplit = prev.nextSibling;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -39,7 +39,7 @@ function isContainer ( node ) {
|
|||
}
|
||||
|
||||
function getBlockWalker ( node, root ) {
|
||||
var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock, false );
|
||||
var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock );
|
||||
walker.currentNode = node;
|
||||
return walker;
|
||||
}
|
||||
|
|
|
@ -257,13 +257,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
|
|||
// merge containers at the edges.
|
||||
next = nodeBeforeSplit.nextSibling;
|
||||
node = getPreviousBlock( next, root );
|
||||
if ( !/\S/.test( node.textContent ) ) {
|
||||
if ( node && !/\S/.test( node.textContent ) ) {
|
||||
do {
|
||||
parent = node.parentNode;
|
||||
parent.removeChild( node );
|
||||
node = parent;
|
||||
} while ( parent && !parent.lastChild &&
|
||||
parent.nodeName !== 'BODY' );
|
||||
} while ( node && !node.lastChild && node !== root );
|
||||
}
|
||||
if ( !nodeBeforeSplit.parentNode ) {
|
||||
nodeBeforeSplit = next.previousSibling;
|
||||
|
@ -281,13 +280,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
|
|||
prev = nodeAfterSplit.previousSibling;
|
||||
node = isBlock( nodeAfterSplit ) ?
|
||||
nodeAfterSplit : getNextBlock( nodeAfterSplit, root );
|
||||
if ( !/\S/.test( node.textContent ) ) {
|
||||
if ( node && !/\S/.test( node.textContent ) ) {
|
||||
do {
|
||||
parent = node.parentNode;
|
||||
parent.removeChild( node );
|
||||
node = parent;
|
||||
} while ( parent && !parent.lastChild &&
|
||||
parent.nodeName !== 'BODY' );
|
||||
} while ( node && !node.lastChild && node !== root );
|
||||
}
|
||||
if ( !nodeAfterSplit.parentNode ) {
|
||||
nodeAfterSplit = prev.nextSibling;
|
||||
|
|
Loading…
Reference in a new issue