0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Don't crash removing list if no <li> inside

This commit is contained in:
Neil Jenkins 2018-10-19 11:54:05 +11:00
parent 7cef58bda8
commit 892986b17c
3 changed files with 53 additions and 49 deletions

View file

@ -4086,6 +4086,7 @@ proto.decreaseListLevel = function ( range ) {
var list = listSelection[0];
var startLi = listSelection[1];
var endLi = listSelection[2];
var newParent, next, insertBefore, makeNotList;
if ( !startLi ) {
startLi = list.firstChild;
}
@ -4096,35 +4097,36 @@ proto.decreaseListLevel = function ( range ) {
// Save undo checkpoint and bookmark selection
this._recordUndoState( range, this._isInUndoState );
// Find the new parent list node
var newParent = list.parentNode;
var next;
if ( startLi ) {
// Find the new parent list node
newParent = list.parentNode;
// Split list if necesary
var insertBefore = !endLi.nextSibling ?
list.nextSibling :
split( list, endLi.nextSibling, newParent, root );
// Split list if necesary
insertBefore = !endLi.nextSibling ?
list.nextSibling :
split( list, endLi.nextSibling, newParent, root );
if ( newParent !== root && newParent.nodeName === 'LI' ) {
newParent = newParent.parentNode;
while ( insertBefore ) {
next = insertBefore.nextSibling;
endLi.appendChild( insertBefore );
insertBefore = next;
if ( newParent !== root && newParent.nodeName === 'LI' ) {
newParent = newParent.parentNode;
while ( insertBefore ) {
next = insertBefore.nextSibling;
endLi.appendChild( insertBefore );
insertBefore = next;
}
insertBefore = list.parentNode.nextSibling;
}
insertBefore = list.parentNode.nextSibling;
makeNotList = !/^[OU]L$/.test( newParent.nodeName );
do {
next = startLi === endLi ? null : startLi.nextSibling;
list.removeChild( startLi );
if ( makeNotList && startLi.nodeName === 'LI' ) {
startLi = this.createDefaultBlock([ empty( startLi ) ]);
}
newParent.insertBefore( startLi, insertBefore );
} while (( startLi = next ));
}
var makeNotList = !/^[OU]L$/.test( newParent.nodeName );
do {
next = startLi === endLi ? null : startLi.nextSibling;
list.removeChild( startLi );
if ( makeNotList && startLi.nodeName === 'LI' ) {
startLi = this.createDefaultBlock([ empty( startLi ) ]);
}
newParent.insertBefore( startLi, insertBefore );
} while ( ( startLi = next ) );
if ( !list.firstChild ) {
detach( list );
}

File diff suppressed because one or more lines are too long

View file

@ -1550,6 +1550,7 @@ proto.decreaseListLevel = function ( range ) {
var list = listSelection[0];
var startLi = listSelection[1];
var endLi = listSelection[2];
var newParent, next, insertBefore, makeNotList;
if ( !startLi ) {
startLi = list.firstChild;
}
@ -1560,35 +1561,36 @@ proto.decreaseListLevel = function ( range ) {
// Save undo checkpoint and bookmark selection
this._recordUndoState( range, this._isInUndoState );
// Find the new parent list node
var newParent = list.parentNode;
var next;
if ( startLi ) {
// Find the new parent list node
newParent = list.parentNode;
// Split list if necesary
var insertBefore = !endLi.nextSibling ?
list.nextSibling :
split( list, endLi.nextSibling, newParent, root );
// Split list if necesary
insertBefore = !endLi.nextSibling ?
list.nextSibling :
split( list, endLi.nextSibling, newParent, root );
if ( newParent !== root && newParent.nodeName === 'LI' ) {
newParent = newParent.parentNode;
while ( insertBefore ) {
next = insertBefore.nextSibling;
endLi.appendChild( insertBefore );
insertBefore = next;
if ( newParent !== root && newParent.nodeName === 'LI' ) {
newParent = newParent.parentNode;
while ( insertBefore ) {
next = insertBefore.nextSibling;
endLi.appendChild( insertBefore );
insertBefore = next;
}
insertBefore = list.parentNode.nextSibling;
}
insertBefore = list.parentNode.nextSibling;
makeNotList = !/^[OU]L$/.test( newParent.nodeName );
do {
next = startLi === endLi ? null : startLi.nextSibling;
list.removeChild( startLi );
if ( makeNotList && startLi.nodeName === 'LI' ) {
startLi = this.createDefaultBlock([ empty( startLi ) ]);
}
newParent.insertBefore( startLi, insertBefore );
} while (( startLi = next ));
}
var makeNotList = !/^[OU]L$/.test( newParent.nodeName );
do {
next = startLi === endLi ? null : startLi.nextSibling;
list.removeChild( startLi );
if ( makeNotList && startLi.nodeName === 'LI' ) {
startLi = this.createDefaultBlock([ empty( startLi ) ]);
}
newParent.insertBefore( startLi, insertBefore );
} while ( ( startLi = next ) );
if ( !list.firstChild ) {
detach( list );
}