mirror of
https://github.com/fastmail/Squire.git
synced 2024-12-22 07:13:08 -05:00
Squire#removeAllFormatting fixes.
* Update the path after making the changes, so UI buttons can update correctly. * Focus the editor on completion, to match the behaviour of other commands. * Merge all the gathered text nodes if they're adjacent, so we have a normalised result.
This commit is contained in:
parent
09167c73e4
commit
a1ff33da9f
4 changed files with 50 additions and 16 deletions
|
@ -172,7 +172,7 @@ function hasTagAttributes ( node, tag, attributes ) {
|
|||
return true;
|
||||
}
|
||||
function areAlike ( node, node2 ) {
|
||||
return (
|
||||
return !isLeaf( node ) && (
|
||||
node.nodeType === node2.nodeType &&
|
||||
node.nodeName === node2.nodeName &&
|
||||
node.className === node2.className &&
|
||||
|
@ -3697,7 +3697,7 @@ proto.removeAllFormatting = function ( range ) {
|
|||
var cleanNodes = doc.createDocumentFragment();
|
||||
var nodeAfterSplit = split( endContainer, endOffset, stopNode );
|
||||
var nodeInSplit = split( startContainer, startOffset, stopNode );
|
||||
var nextNode;
|
||||
var nextNode, _range, childNodes;
|
||||
|
||||
// Then replace contents in split with a cleaned version of the same:
|
||||
// blocks become default blocks, text and leaf nodes survive, everything
|
||||
|
@ -3708,22 +3708,39 @@ proto.removeAllFormatting = function ( range ) {
|
|||
nodeInSplit = nextNode;
|
||||
}
|
||||
removeFormatting( this, formattedNodes, cleanNodes );
|
||||
cleanNodes.normalize();
|
||||
nodeInSplit = cleanNodes.firstChild;
|
||||
nextNode = cleanNodes.lastChild;
|
||||
|
||||
// Restore selection
|
||||
childNodes = stopNode.childNodes;
|
||||
if ( nodeInSplit ) {
|
||||
stopNode.insertBefore( cleanNodes, nodeAfterSplit );
|
||||
range.setStartBefore( nodeInSplit );
|
||||
range.setEndAfter( nextNode );
|
||||
startOffset = indexOf.call( childNodes, nodeInSplit );
|
||||
endOffset = indexOf.call( childNodes, nextNode ) + 1;
|
||||
} else {
|
||||
range.setStartBefore( nodeAfterSplit );
|
||||
range.setEndBefore( nodeAfterSplit );
|
||||
startOffset = indexOf.call( childNodes, nodeAfterSplit );
|
||||
endOffset = startOffset;
|
||||
}
|
||||
|
||||
// Merge text nodes at edges, if possible
|
||||
_range = {
|
||||
startContainer: stopNode,
|
||||
startOffset: startOffset,
|
||||
endContainer: stopNode,
|
||||
endOffset: endOffset
|
||||
};
|
||||
mergeInlines( stopNode, _range );
|
||||
range.setStart( _range.startContainer, _range.startOffset );
|
||||
range.setEnd( _range.endContainer, _range.endOffset );
|
||||
|
||||
// And move back down the tree
|
||||
moveRangeBoundariesDownTree( range );
|
||||
|
||||
this.setSelection( range );
|
||||
this._updatePath( range, true );
|
||||
|
||||
return this;
|
||||
return this.focus();
|
||||
};
|
||||
|
||||
proto.increaseQuoteLevel = command( 'modifyBlocks', increaseBlockQuoteLevel );
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2220,7 +2220,7 @@ proto.removeAllFormatting = function ( range ) {
|
|||
var cleanNodes = doc.createDocumentFragment();
|
||||
var nodeAfterSplit = split( endContainer, endOffset, stopNode );
|
||||
var nodeInSplit = split( startContainer, startOffset, stopNode );
|
||||
var nextNode;
|
||||
var nextNode, _range, childNodes;
|
||||
|
||||
// Then replace contents in split with a cleaned version of the same:
|
||||
// blocks become default blocks, text and leaf nodes survive, everything
|
||||
|
@ -2231,22 +2231,39 @@ proto.removeAllFormatting = function ( range ) {
|
|||
nodeInSplit = nextNode;
|
||||
}
|
||||
removeFormatting( this, formattedNodes, cleanNodes );
|
||||
cleanNodes.normalize();
|
||||
nodeInSplit = cleanNodes.firstChild;
|
||||
nextNode = cleanNodes.lastChild;
|
||||
|
||||
// Restore selection
|
||||
childNodes = stopNode.childNodes;
|
||||
if ( nodeInSplit ) {
|
||||
stopNode.insertBefore( cleanNodes, nodeAfterSplit );
|
||||
range.setStartBefore( nodeInSplit );
|
||||
range.setEndAfter( nextNode );
|
||||
startOffset = indexOf.call( childNodes, nodeInSplit );
|
||||
endOffset = indexOf.call( childNodes, nextNode ) + 1;
|
||||
} else {
|
||||
range.setStartBefore( nodeAfterSplit );
|
||||
range.setEndBefore( nodeAfterSplit );
|
||||
startOffset = indexOf.call( childNodes, nodeAfterSplit );
|
||||
endOffset = startOffset;
|
||||
}
|
||||
|
||||
// Merge text nodes at edges, if possible
|
||||
_range = {
|
||||
startContainer: stopNode,
|
||||
startOffset: startOffset,
|
||||
endContainer: stopNode,
|
||||
endOffset: endOffset
|
||||
};
|
||||
mergeInlines( stopNode, _range );
|
||||
range.setStart( _range.startContainer, _range.startOffset );
|
||||
range.setEnd( _range.endContainer, _range.endOffset );
|
||||
|
||||
// And move back down the tree
|
||||
moveRangeBoundariesDownTree( range );
|
||||
|
||||
this.setSelection( range );
|
||||
this._updatePath( range, true );
|
||||
|
||||
return this;
|
||||
return this.focus();
|
||||
};
|
||||
|
||||
proto.increaseQuoteLevel = command( 'modifyBlocks', increaseBlockQuoteLevel );
|
||||
|
|
|
@ -32,7 +32,7 @@ function hasTagAttributes ( node, tag, attributes ) {
|
|||
return true;
|
||||
}
|
||||
function areAlike ( node, node2 ) {
|
||||
return (
|
||||
return !isLeaf( node ) && (
|
||||
node.nodeType === node2.nodeType &&
|
||||
node.nodeName === node2.nodeName &&
|
||||
node.className === node2.className &&
|
||||
|
|
Loading…
Reference in a new issue