mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Fix cleanup empty <a> on enter in WebKit/Blink
Need to consider zero-width space equivalent to no content. Also cleanup empty inline nodes in general when cleaning up zero-width spaces inside them. Fixes #58
This commit is contained in:
parent
1c0fa1a50f
commit
7db0ae059a
3 changed files with 34 additions and 12 deletions
|
@ -1410,10 +1410,19 @@ var removeZWS = function ( root ) {
|
|||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||
return true;
|
||||
}, false ),
|
||||
node, index;
|
||||
parent, node, index;
|
||||
while ( node = walker.nextNode() ) {
|
||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 ) {
|
||||
node.deleteData( index, 1 );
|
||||
if ( node.length === 1 ) {
|
||||
do {
|
||||
parent = node.parentNode;
|
||||
parent.removeChild( node );
|
||||
node = parent;
|
||||
} while ( isInline( node ) && !getLength( node ) );
|
||||
break;
|
||||
} else {
|
||||
node.deleteData( index, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -2879,10 +2888,12 @@ var keyHandlers = {
|
|||
// Don't continue links over a block break; unlikely to be the
|
||||
// desired outcome.
|
||||
if ( nodeAfterSplit.nodeName === 'A' &&
|
||||
!nodeAfterSplit.textContent ) {
|
||||
replaceWith( nodeAfterSplit, empty( nodeAfterSplit ) );
|
||||
( !nodeAfterSplit.textContent ||
|
||||
nodeAfterSplit.textContent === ZWS ) ) {
|
||||
child = self._doc.createTextNode( '' );
|
||||
replaceWith( nodeAfterSplit, child );
|
||||
nodeAfterSplit = child;
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
while ( child && child.nodeType === TEXT_NODE && !child.data ) {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -357,10 +357,19 @@ var removeZWS = function ( root ) {
|
|||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||
return true;
|
||||
}, false ),
|
||||
node, index;
|
||||
parent, node, index;
|
||||
while ( node = walker.nextNode() ) {
|
||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 ) {
|
||||
node.deleteData( index, 1 );
|
||||
if ( node.length === 1 ) {
|
||||
do {
|
||||
parent = node.parentNode;
|
||||
parent.removeChild( node );
|
||||
node = parent;
|
||||
} while ( isInline( node ) && !getLength( node ) );
|
||||
break;
|
||||
} else {
|
||||
node.deleteData( index, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1826,10 +1835,12 @@ var keyHandlers = {
|
|||
// Don't continue links over a block break; unlikely to be the
|
||||
// desired outcome.
|
||||
if ( nodeAfterSplit.nodeName === 'A' &&
|
||||
!nodeAfterSplit.textContent ) {
|
||||
replaceWith( nodeAfterSplit, empty( nodeAfterSplit ) );
|
||||
( !nodeAfterSplit.textContent ||
|
||||
nodeAfterSplit.textContent === ZWS ) ) {
|
||||
child = self._doc.createTextNode( '' );
|
||||
replaceWith( nodeAfterSplit, child );
|
||||
nodeAfterSplit = child;
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
while ( child && child.nodeType === TEXT_NODE && !child.data ) {
|
||||
|
|
Loading…
Reference in a new issue