0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 15:23:29 -05:00

Add guard for null nodes in insertTreeFragmentIntoRange

This commit is contained in:
Neil Jenkins 2016-04-08 17:42:47 +10:00
parent 66c0b20702
commit 44a2b5c7a8
4 changed files with 12 additions and 16 deletions

View file

@ -210,7 +210,7 @@ function isContainer ( node ) {
} }
function getBlockWalker ( node, root ) { function getBlockWalker ( node, root ) {
var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock, false ); var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock );
walker.currentNode = node; walker.currentNode = node;
return walker; return walker;
} }
@ -914,13 +914,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
// merge containers at the edges. // merge containers at the edges.
next = nodeBeforeSplit.nextSibling; next = nodeBeforeSplit.nextSibling;
node = getPreviousBlock( next, root ); node = getPreviousBlock( next, root );
if ( !/\S/.test( node.textContent ) ) { if ( node && !/\S/.test( node.textContent ) ) {
do { do {
parent = node.parentNode; parent = node.parentNode;
parent.removeChild( node ); parent.removeChild( node );
node = parent; node = parent;
} while ( parent && !parent.lastChild && } while ( node && !node.lastChild && node !== root );
parent.nodeName !== 'BODY' );
} }
if ( !nodeBeforeSplit.parentNode ) { if ( !nodeBeforeSplit.parentNode ) {
nodeBeforeSplit = next.previousSibling; nodeBeforeSplit = next.previousSibling;
@ -938,13 +937,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
prev = nodeAfterSplit.previousSibling; prev = nodeAfterSplit.previousSibling;
node = isBlock( nodeAfterSplit ) ? node = isBlock( nodeAfterSplit ) ?
nodeAfterSplit : getNextBlock( nodeAfterSplit, root ); nodeAfterSplit : getNextBlock( nodeAfterSplit, root );
if ( !/\S/.test( node.textContent ) ) { if ( node && !/\S/.test( node.textContent ) ) {
do { do {
parent = node.parentNode; parent = node.parentNode;
parent.removeChild( node ); parent.removeChild( node );
node = parent; node = parent;
} while ( parent && !parent.lastChild && } while ( node && !node.lastChild && node !== root );
parent.nodeName !== 'BODY' );
} }
if ( !nodeAfterSplit.parentNode ) { if ( !nodeAfterSplit.parentNode ) {
nodeAfterSplit = prev.nextSibling; nodeAfterSplit = prev.nextSibling;

File diff suppressed because one or more lines are too long

View file

@ -39,7 +39,7 @@ function isContainer ( node ) {
} }
function getBlockWalker ( node, root ) { function getBlockWalker ( node, root ) {
var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock, false ); var walker = new TreeWalker( root, SHOW_ELEMENT, isBlock );
walker.currentNode = node; walker.currentNode = node;
return walker; return walker;
} }

View file

@ -257,13 +257,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
// merge containers at the edges. // merge containers at the edges.
next = nodeBeforeSplit.nextSibling; next = nodeBeforeSplit.nextSibling;
node = getPreviousBlock( next, root ); node = getPreviousBlock( next, root );
if ( !/\S/.test( node.textContent ) ) { if ( node && !/\S/.test( node.textContent ) ) {
do { do {
parent = node.parentNode; parent = node.parentNode;
parent.removeChild( node ); parent.removeChild( node );
node = parent; node = parent;
} while ( parent && !parent.lastChild && } while ( node && !node.lastChild && node !== root );
parent.nodeName !== 'BODY' );
} }
if ( !nodeBeforeSplit.parentNode ) { if ( !nodeBeforeSplit.parentNode ) {
nodeBeforeSplit = next.previousSibling; nodeBeforeSplit = next.previousSibling;
@ -281,13 +280,12 @@ var insertTreeFragmentIntoRange = function ( range, frag, root ) {
prev = nodeAfterSplit.previousSibling; prev = nodeAfterSplit.previousSibling;
node = isBlock( nodeAfterSplit ) ? node = isBlock( nodeAfterSplit ) ?
nodeAfterSplit : getNextBlock( nodeAfterSplit, root ); nodeAfterSplit : getNextBlock( nodeAfterSplit, root );
if ( !/\S/.test( node.textContent ) ) { if ( node && !/\S/.test( node.textContent ) ) {
do { do {
parent = node.parentNode; parent = node.parentNode;
parent.removeChild( node ); parent.removeChild( node );
node = parent; node = parent;
} while ( parent && !parent.lastChild && } while ( node && !node.lastChild && node !== root );
parent.nodeName !== 'BODY' );
} }
if ( !nodeAfterSplit.parentNode ) { if ( !nodeAfterSplit.parentNode ) {
nodeAfterSplit = prev.nextSibling; nodeAfterSplit = prev.nextSibling;