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

Remove uneditable container entirely on delete/backspace

If you backspace/delete to remove an uneditable block, we should be checking if
it's part of a larger uneditable container and if so removing the whole thing.
This commit is contained in:
Neil Jenkins 2020-03-29 13:42:15 +11:00
parent 374d067ef3
commit e1e8ec78cb
3 changed files with 27 additions and 5 deletions

View file

@ -1380,6 +1380,17 @@ var afterDelete = function ( self, range ) {
}
};
var detachUneditableNode = function ( node, root ) {
var parent;
while (( parent = node.parentNode )) {
if ( parent === root || parent.isContentEditable ) {
break;
}
node = parent;
}
detach( node );
};
var handleEnter = function ( self, shiftKey, range ) {
var root = self._root;
var block, parent, node, offset, nodeAfterSplit;
@ -1593,7 +1604,7 @@ var keyHandlers = {
if ( previous ) {
// If not editable, just delete whole block.
if ( !previous.isContentEditable ) {
detach( previous );
detachUneditableNode( previous, root );
return;
}
// Otherwise merge.
@ -1660,7 +1671,7 @@ var keyHandlers = {
if ( next ) {
// If not editable, just delete whole block.
if ( !next.isContentEditable ) {
detach( next );
detachUneditableNode( next, root );
return;
}
// Otherwise merge.

File diff suppressed because one or more lines are too long

View file

@ -139,6 +139,17 @@ var afterDelete = function ( self, range ) {
}
};
var detachUneditableNode = function ( node, root ) {
var parent;
while (( parent = node.parentNode )) {
if ( parent === root || parent.isContentEditable ) {
break;
}
node = parent;
}
detach( node );
};
var handleEnter = function ( self, shiftKey, range ) {
var root = self._root;
var block, parent, node, offset, nodeAfterSplit;
@ -352,7 +363,7 @@ var keyHandlers = {
if ( previous ) {
// If not editable, just delete whole block.
if ( !previous.isContentEditable ) {
detach( previous );
detachUneditableNode( previous, root );
return;
}
// Otherwise merge.
@ -419,7 +430,7 @@ var keyHandlers = {
if ( next ) {
// If not editable, just delete whole block.
if ( !next.isContentEditable ) {
detach( next );
detachUneditableNode( next, root );
return;
}
// Otherwise merge.