Esanders has uploaded a new change for review. https://gerrit.wikimedia.org/r/116754
Change subject: Use previous breakpoint's range when undoing ...................................................................... Use previous breakpoint's range when undoing We store ranges in breakpoints and apply them directly when redoing. However when undoing we take the range and use Transaction#translateRange to calculate the previous range. Apart from being buggy because translateRange is theoretically impossible to do properly (e.g. when ranges collapse to zero width then expand again) this is also overly complex as we can just get the range from the previous breakpoint (or use [1,1] if this is the first breakpoint). Bonus: * Correct offset in purgeHistory (although this method is never used) * Remove unused param from breakpoint() Bug: 62088 Change-Id: Ic19ef19cfbb1fabac9153bc0c4cd56e5dffdc2c4 --- M modules/ve/dm/ve.dm.Surface.js 1 file changed, 9 insertions(+), 9 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/VisualEditor/VisualEditor refs/changes/54/116754/1 diff --git a/modules/ve/dm/ve.dm.Surface.js b/modules/ve/dm/ve.dm.Surface.js index 4a741f0..3227a0f 100644 --- a/modules/ve/dm/ve.dm.Surface.js +++ b/modules/ve/dm/ve.dm.Surface.js @@ -131,7 +131,7 @@ if ( !this.enabled ) { return; } - this.selection = new ve.Range( 0, 0 ); + this.selection = new ve.Range( 1, 1 ); this.newTransactions = []; this.undoStack = []; this.undoIndex = 0; @@ -521,18 +521,17 @@ * Set a history state breakpoint. * * @method - * @param {ve.Range} selection New selection range * @fires history * @returns {boolean} A breakpoint was added */ -ve.dm.Surface.prototype.breakpoint = function ( selection ) { +ve.dm.Surface.prototype.breakpoint = function () { if ( !this.enabled ) { return false; } if ( this.newTransactions.length > 0 ) { this.undoStack.push( { 'transactions': this.newTransactions, - 'selection': selection || this.selection.clone() + 'selection': this.selection.clone() } ); this.newTransactions = []; this.emit( 'history' ); @@ -548,7 +547,7 @@ * @fires history */ ve.dm.Surface.prototype.undo = function () { - var i, item, selection, transaction, transactions = []; + var i, item, prevItem, prevSelection, transaction, transactions = []; if ( !this.enabled || !this.hasPastState() ) { return; } @@ -558,14 +557,15 @@ item = this.undoStack[this.undoStack.length - this.undoIndex]; if ( item ) { - // Apply reversed transactions in reversed order, and translate the selection accordingly - selection = item.selection; + // Apply reversed transactions in reversed order for ( i = item.transactions.length - 1; i >= 0; i-- ) { transaction = item.transactions[i].reversed(); - selection = transaction.translateRange( selection ); transactions.push( transaction ); } - this.changeInternal( transactions, selection, true ); + // Get selection from previous item in stack + prevItem = this.undoStack[this.undoStack.length - this.undoIndex - 1]; + prevSelection = prevItem ? prevItem.selection : new ve.Range( 1, 1 ); + this.changeInternal( transactions, prevSelection, true ); this.emit( 'history' ); } }; -- To view, visit https://gerrit.wikimedia.org/r/116754 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic19ef19cfbb1fabac9153bc0c4cd56e5dffdc2c4 Gerrit-PatchSet: 1 Gerrit-Project: VisualEditor/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits