jenkins-bot has submitted this change and it was merged.
Change subject: Optionally allow undo while staging
......................................................................
Optionally allow undo while staging
Change-Id: I93afcc0937d59c0367a36aa9a27b2e3fd27da6d8
---
M modules/ve/dm/ve.dm.Surface.js
M modules/ve/test/dm/ve.dm.Surface.test.js
2 files changed, 41 insertions(+), 9 deletions(-)
Approvals:
Trevor Parscal: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/ve/dm/ve.dm.Surface.js b/modules/ve/dm/ve.dm.Surface.js
index 47c0adc..ac06318 100644
--- a/modules/ve/dm/ve.dm.Surface.js
+++ b/modules/ve/dm/ve.dm.Surface.js
@@ -152,6 +152,27 @@
};
/**
+ * Get the staging state at the current staging stack depth
+ *
+ * @returns {Object|undefined} staging Staging state object, or undefined if
not staging
+ * @returns {ve.dm.Transaction[]} staging.transactions Staging transactions
+ * @returns {boolean} staging.allowUndo Allow undo while staging
+ */
+ve.dm.Surface.prototype.getStaging = function () {
+ return this.stagingStack[this.stagingStack.length - 1];
+};
+
+/**
+ * Undo is allowed at the current staging stack depth
+ *
+ * @returns {boolean|undefined} Undo is allowed, or undefined if not staging
+ */
+ve.dm.Surface.prototype.doesStagingAllowUndo = function () {
+ var staging = this.getStaging();
+ return staging && staging.allowUndo;
+};
+
+/**
* Get the staging transactions at the current staging stack depth
*
* The array is returned by reference so it can be pushed to.
@@ -159,15 +180,17 @@
* @returns {ve.dm.Transaction[]|undefined} Staging transactions, or undefined
if not staging
*/
ve.dm.Surface.prototype.getStagingTransactions = function () {
- return this.stagingStack[this.stagingStack.length - 1];
+ var staging = this.getStaging();
+ return staging && staging.transactions;
};
/**
* Push another level of staging to the staging stack
*
+ * @param {boolean} [allowUndo=false] Allow undo while staging
* @fires history
*/
-ve.dm.Surface.prototype.pushStaging = function () {
+ve.dm.Surface.prototype.pushStaging = function ( allowUndo ) {
// If we're starting staging stop history tracking
if ( !this.isStaging() ) {
// Set a breakpoint to make sure newTransactions is clear
@@ -175,7 +198,7 @@
this.stopHistoryTracking();
this.emit( 'history' );
}
- this.stagingStack.push( [] );
+ this.stagingStack.push( { 'transactions': [], 'allowUndo': !!allowUndo
} );
};
/**
@@ -191,7 +214,8 @@
var i, transaction,
reverseTransactions = [],
- transactions = this.stagingStack.pop();
+ staging = this.stagingStack.pop(),
+ transactions = staging.transactions;
// Not applying, so rollback transactions
for ( i = transactions.length - 1; i >= 0; i-- ) {
@@ -218,7 +242,8 @@
return;
}
- var transactions = this.stagingStack.pop();
+ var staging = this.stagingStack.pop(),
+ transactions = staging.transactions;
if ( this.isStaging() ) {
// Move transactions to the next item down in the staging stack
@@ -347,7 +372,7 @@
* @returns {boolean} Redo is allowed
*/
ve.dm.Surface.prototype.canRedo = function () {
- return this.undoIndex > 0 && this.enabled && !this.isStaging();
+ return this.undoIndex > 0 && this.enabled;
};
/**
@@ -357,7 +382,7 @@
* @returns {boolean} Undo is allowed
*/
ve.dm.Surface.prototype.canUndo = function () {
- return this.hasBeenModified() && this.enabled && !this.isStaging();
+ return this.hasBeenModified() && this.enabled && ( !this.isStaging() ||
this.doesStagingAllowUndo() );
};
/**
@@ -700,6 +725,10 @@
return;
}
+ if ( this.isStaging() ) {
+ this.popAllStaging();
+ }
+
this.breakpoint();
this.undoIndex++;
diff --git a/modules/ve/test/dm/ve.dm.Surface.test.js
b/modules/ve/test/dm/ve.dm.Surface.test.js
index 9810daf..dc65464 100644
--- a/modules/ve/test/dm/ve.dm.Surface.test.js
+++ b/modules/ve/test/dm/ve.dm.Surface.test.js
@@ -85,7 +85,7 @@
assert.deepEqual( surface.newTransactions, [], 'New transactions match
after breakpoint' );
} );
-QUnit.test( 'staging', 23, function ( assert ) {
+QUnit.test( 'staging', 26, function ( assert ) {
var tx1, tx2,
surface = new ve.dm.SurfaceStub(),
fragment = surface.getFragment( new ve.Range( 1, 3 ) ),
@@ -93,12 +93,14 @@
assert.equal( surface.isStaging(), false, 'isStaging false when not
staging' );
assert.equal( surface.getStagingTransactions(), undefined,
'getStagingTransactions undefined when not staging' );
+ assert.equal( surface.doesStagingAllowUndo(), undefined,
'doesStagingAllowUndo undefined when not staging' );
surface.change( new ve.dm.Transaction.newFromInsertion( doc, 1, ['a'] )
);
surface.pushStaging();
assert.equal( surface.isStaging(), true, 'isStaging true after
pushStaging' );
assert.deepEqual( surface.getStagingTransactions(), [],
'getStagingTransactions empty array after pushStaging' );
+ assert.equal( surface.doesStagingAllowUndo(), false,
'doesStagingAllowUndo false when staging without undo' );
tx1 = new ve.dm.Transaction.newFromInsertion( doc, 2, ['b'] );
surface.change( tx1 );
@@ -106,9 +108,10 @@
assert.equal( fragment.getText(), 'abhi', 'document contents match
after first transaction' );
assert.deepEqual( surface.getStagingTransactions(), [tx1],
'getStagingTransactions contains first transaction after change' );
- surface.pushStaging();
+ surface.pushStaging( true );
assert.equal( surface.isStaging(), true, 'isStaging true after nested
pushStaging' );
assert.deepEqual( surface.getStagingTransactions(), [],
'getStagingTransactions empty array after nested pushStaging' );
+ assert.equal( surface.doesStagingAllowUndo(), true,
'doesStagingAllowUndo true when staging with undo' );
tx2 = new ve.dm.Transaction.newFromInsertion( doc, 3, ['c'] );
surface.change( tx2 );
--
To view, visit https://gerrit.wikimedia.org/r/135130
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I93afcc0937d59c0367a36aa9a27b2e3fd27da6d8
Gerrit-PatchSet: 3
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Esanders <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits