mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-25 11:16:51 +00:00
Added isNoOp to ve.dm.Transaction
Also added some checks in content branch conversion to make sure that converting from and to the same thing results in a no-op Change-Id: Ie47520d666e45a77d12c7ebb9457aef7ab6b8097
This commit is contained in:
parent
fed1a98dd7
commit
a0fa371481
|
@ -88,7 +88,7 @@ ve.dm.Surface.prototype.getFragment = function () {
|
|||
* @param {ve.Range|undefined} selection
|
||||
*/
|
||||
ve.dm.Surface.prototype.change = function ( transaction, selection ) {
|
||||
if ( transaction ) {
|
||||
if ( transaction && !transaction.isNoOp() ) {
|
||||
this.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex );
|
||||
this.undoIndex = 0;
|
||||
this.smallStack.push( transaction );
|
||||
|
|
|
@ -278,6 +278,10 @@ ve.dm.Transaction.newFromContentBranchConversion = function ( doc, range, type,
|
|||
selected = selection[i];
|
||||
if ( selected.node.isContent() ) {
|
||||
branch = selected.node.getParent();
|
||||
// Skip branches that are already of the target type and have identical attributes
|
||||
if ( branch.getType() === type && ve.compareObjects( branch.getAttributes(), attr ) ) {
|
||||
continue;
|
||||
}
|
||||
branchOuterRange = branch.getOuterRange();
|
||||
// Don't convert the same branch twice
|
||||
if ( branch === previousBranch ) {
|
||||
|
@ -443,6 +447,22 @@ ve.dm.Transaction.newFromWrap = function ( doc, range, unwrapOuter, wrapOuter, u
|
|||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Checks if transaction would make any actual changes if processed.
|
||||
*
|
||||
* There may be more sophisticated checks that can be done, like looking for things being replaced
|
||||
* with identical content, but such transactions probably should not be created in the first place.
|
||||
*
|
||||
* @method
|
||||
* @returns {Boolean} Transaction is no-op
|
||||
*/
|
||||
ve.dm.Transaction.prototype.isNoOp = function () {
|
||||
return (
|
||||
this.operations.length === 0 ||
|
||||
( this.operations.length === 1 && this.operations[0].type === 'retain' )
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a list of all operations.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue