jenkins-bot has submitted this change and it was merged.

Change subject: DM Surface: Cleanup emission of 'history' event
......................................................................


DM Surface: Cleanup emission of 'history' event

* Emit history as soon as transactions are applied from inside changeInternal
* This removes the need to emit it manually from undo/redo
* Remove from truncateUndoStack as all callers eventually emit it
* Remove from breakpoint as moving transactions from newTransactions
  to the undo stack doesn't meaningfully change the history state.

Bug: T115483
Change-Id: Ie36d4b06174f2aa264860bbb310d83198c978add
---
M src/dm/ve.dm.Surface.js
1 file changed, 3 insertions(+), 11 deletions(-)

Approvals:
  DLynch: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/dm/ve.dm.Surface.js b/src/dm/ve.dm.Surface.js
index 91c188e..eac120b 100644
--- a/src/dm/ve.dm.Surface.js
+++ b/src/dm/ve.dm.Surface.js
@@ -211,7 +211,6 @@
  * 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 ( allowUndo ) {
        // If we're starting staging stop history tracking
@@ -487,13 +486,12 @@
 /**
  * Prevent future states from being redone.
  *
- * @fires history
+ * Callers should eventually emit a 'history' event after using this method.
  */
 ve.dm.Surface.prototype.truncateUndoStack = function () {
        if ( this.undoIndex ) {
                this.undoStack = this.undoStack.slice( 0, this.undoStack.length 
- this.undoIndex );
                this.undoIndex = 0;
-               this.emit( 'history' );
        }
 };
 
@@ -782,6 +780,7 @@
  * @param {ve.dm.Selection} [selection] [selection]
  * @param {boolean} [skipUndoStack=false] If true, do not modify the undo 
stack. Used by undo/redo
  * @fires select
+ * @fires history
  * @fires contextChange
  */
 ve.dm.Surface.prototype.changeInternal = function ( transactions, selection, 
skipUndoStack ) {
@@ -825,6 +824,7 @@
                        }
                }
                this.transacting = false;
+               this.emit( 'history' );
        }
        selectionAfter = this.selection;
 
@@ -856,7 +856,6 @@
 /**
  * Set a history state breakpoint.
  *
- * @fires history
  * @return {boolean} A breakpoint was added
  */
 ve.dm.Surface.prototype.breakpoint = function () {
@@ -870,7 +869,6 @@
                        selectionBefore: this.selectionBefore.clone()
                } );
                this.newTransactions = [];
-               this.emit( 'history' );
                return true;
        } else if ( this.selectionBefore.isNull() && !this.selection.isNull() ) 
{
                this.selectionBefore = this.selection.clone();
@@ -880,8 +878,6 @@
 
 /**
  * Step backwards in history.
- *
- * @fires history
  */
 ve.dm.Surface.prototype.undo = function () {
        var i, item, transaction, transactions = [];
@@ -904,14 +900,11 @@
                        transactions.push( transaction );
                }
                this.changeInternal( transactions, item.selectionBefore, true );
-               this.emit( 'history' );
        }
 };
 
 /**
  * Step forwards in history.
- *
- * @fires history
  */
 ve.dm.Surface.prototype.redo = function () {
        var item;
@@ -926,7 +919,6 @@
                // ve.copy( item.transactions ) invokes .clone() on each 
transaction in item.transactions
                this.changeInternal( ve.copy( item.transactions ), 
item.selection, true );
                this.undoIndex--;
-               this.emit( 'history' );
        }
 };
 

-- 
To view, visit https://gerrit.wikimedia.org/r/246250
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie36d4b06174f2aa264860bbb310d83198c978add
Gerrit-PatchSet: 2
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: DLynch <[email protected]>
Gerrit-Reviewer: Divec <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to