mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +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
|
* @param {ve.Range|undefined} selection
|
||||||
*/
|
*/
|
||||||
ve.dm.Surface.prototype.change = function ( transaction, 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.bigStack = this.bigStack.slice( 0, this.bigStack.length - this.undoIndex );
|
||||||
this.undoIndex = 0;
|
this.undoIndex = 0;
|
||||||
this.smallStack.push( transaction );
|
this.smallStack.push( transaction );
|
||||||
|
|
|
@ -278,6 +278,10 @@ ve.dm.Transaction.newFromContentBranchConversion = function ( doc, range, type,
|
||||||
selected = selection[i];
|
selected = selection[i];
|
||||||
if ( selected.node.isContent() ) {
|
if ( selected.node.isContent() ) {
|
||||||
branch = selected.node.getParent();
|
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();
|
branchOuterRange = branch.getOuterRange();
|
||||||
// Don't convert the same branch twice
|
// Don't convert the same branch twice
|
||||||
if ( branch === previousBranch ) {
|
if ( branch === previousBranch ) {
|
||||||
|
@ -443,6 +447,22 @@ ve.dm.Transaction.newFromWrap = function ( doc, range, unwrapOuter, wrapOuter, u
|
||||||
|
|
||||||
/* Methods */
|
/* 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.
|
* Gets a list of all operations.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue