0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2025-03-11 15:11:23 -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 list = listSelection[0];
var startLi = listSelection[1]; var startLi = listSelection[1];
var endLi = listSelection[2]; var endLi = listSelection[2];
var newParent, next, insertBefore, makeNotList;
if ( !startLi ) { if ( !startLi ) {
startLi = list.firstChild; startLi = list.firstChild;
} }
@ -4096,35 +4097,36 @@ proto.decreaseListLevel = function ( range ) {
// Save undo checkpoint and bookmark selection // Save undo checkpoint and bookmark selection
this._recordUndoState( range, this._isInUndoState ); this._recordUndoState( range, this._isInUndoState );
// Find the new parent list node if ( startLi ) {
var newParent = list.parentNode; // Find the new parent list node
var next; newParent = list.parentNode;
// Split list if necesary // Split list if necesary
var insertBefore = !endLi.nextSibling ? insertBefore = !endLi.nextSibling ?
list.nextSibling : list.nextSibling :
split( list, endLi.nextSibling, newParent, root ); split( list, endLi.nextSibling, newParent, root );
if ( newParent !== root && newParent.nodeName === 'LI' ) { if ( newParent !== root && newParent.nodeName === 'LI' ) {
newParent = newParent.parentNode; newParent = newParent.parentNode;
while ( insertBefore ) { while ( insertBefore ) {
next = insertBefore.nextSibling; next = insertBefore.nextSibling;
endLi.appendChild( insertBefore ); endLi.appendChild( insertBefore );
insertBefore = next; 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 ) { if ( !list.firstChild ) {
detach( list ); 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 list = listSelection[0];
var startLi = listSelection[1]; var startLi = listSelection[1];
var endLi = listSelection[2]; var endLi = listSelection[2];
var newParent, next, insertBefore, makeNotList;
if ( !startLi ) { if ( !startLi ) {
startLi = list.firstChild; startLi = list.firstChild;
} }
@ -1560,35 +1561,36 @@ proto.decreaseListLevel = function ( range ) {
// Save undo checkpoint and bookmark selection // Save undo checkpoint and bookmark selection
this._recordUndoState( range, this._isInUndoState ); this._recordUndoState( range, this._isInUndoState );
// Find the new parent list node if ( startLi ) {
var newParent = list.parentNode; // Find the new parent list node
var next; newParent = list.parentNode;
// Split list if necesary // Split list if necesary
var insertBefore = !endLi.nextSibling ? insertBefore = !endLi.nextSibling ?
list.nextSibling : list.nextSibling :
split( list, endLi.nextSibling, newParent, root ); split( list, endLi.nextSibling, newParent, root );
if ( newParent !== root && newParent.nodeName === 'LI' ) { if ( newParent !== root && newParent.nodeName === 'LI' ) {
newParent = newParent.parentNode; newParent = newParent.parentNode;
while ( insertBefore ) { while ( insertBefore ) {
next = insertBefore.nextSibling; next = insertBefore.nextSibling;
endLi.appendChild( insertBefore ); endLi.appendChild( insertBefore );
insertBefore = next; 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 ) { if ( !list.firstChild ) {
detach( list ); detach( list );
} }