mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-18 12:42:37 -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,12 +1410,21 @@ var removeZWS = function ( root ) {
|
||||||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||||
return true;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
node, index;
|
parent, node, index;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 ) {
|
while ( ( index = node.data.indexOf( ZWS ) ) > -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 );
|
node.deleteData( index, 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
proto._didAddZWS = function () {
|
proto._didAddZWS = function () {
|
||||||
|
@ -2879,10 +2888,12 @@ var keyHandlers = {
|
||||||
// Don't continue links over a block break; unlikely to be the
|
// Don't continue links over a block break; unlikely to be the
|
||||||
// desired outcome.
|
// desired outcome.
|
||||||
if ( nodeAfterSplit.nodeName === 'A' &&
|
if ( nodeAfterSplit.nodeName === 'A' &&
|
||||||
!nodeAfterSplit.textContent ) {
|
( !nodeAfterSplit.textContent ||
|
||||||
replaceWith( nodeAfterSplit, empty( nodeAfterSplit ) );
|
nodeAfterSplit.textContent === ZWS ) ) {
|
||||||
|
child = self._doc.createTextNode( '' );
|
||||||
|
replaceWith( nodeAfterSplit, child );
|
||||||
nodeAfterSplit = child;
|
nodeAfterSplit = child;
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( child && child.nodeType === TEXT_NODE && !child.data ) {
|
while ( child && child.nodeType === TEXT_NODE && !child.data ) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -357,12 +357,21 @@ var removeZWS = function ( root ) {
|
||||||
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
var walker = new TreeWalker( root, SHOW_TEXT, function () {
|
||||||
return true;
|
return true;
|
||||||
}, false ),
|
}, false ),
|
||||||
node, index;
|
parent, node, index;
|
||||||
while ( node = walker.nextNode() ) {
|
while ( node = walker.nextNode() ) {
|
||||||
while ( ( index = node.data.indexOf( ZWS ) ) > -1 ) {
|
while ( ( index = node.data.indexOf( ZWS ) ) > -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 );
|
node.deleteData( index, 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
proto._didAddZWS = function () {
|
proto._didAddZWS = function () {
|
||||||
|
@ -1826,10 +1835,12 @@ var keyHandlers = {
|
||||||
// Don't continue links over a block break; unlikely to be the
|
// Don't continue links over a block break; unlikely to be the
|
||||||
// desired outcome.
|
// desired outcome.
|
||||||
if ( nodeAfterSplit.nodeName === 'A' &&
|
if ( nodeAfterSplit.nodeName === 'A' &&
|
||||||
!nodeAfterSplit.textContent ) {
|
( !nodeAfterSplit.textContent ||
|
||||||
replaceWith( nodeAfterSplit, empty( nodeAfterSplit ) );
|
nodeAfterSplit.textContent === ZWS ) ) {
|
||||||
|
child = self._doc.createTextNode( '' );
|
||||||
|
replaceWith( nodeAfterSplit, child );
|
||||||
nodeAfterSplit = child;
|
nodeAfterSplit = child;
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( child && child.nodeType === TEXT_NODE && !child.data ) {
|
while ( child && child.nodeType === TEXT_NODE && !child.data ) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue