mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Move completeHistory from dm.Surface to dm.Document
Per IRL conversation with Trevor, that's where it belongs. Change-Id: I9eae05380597ed83122f29864b77d2278d3dd863
This commit is contained in:
parent
9c37181788
commit
3d21609ca9
|
@ -51,7 +51,7 @@ ve.inheritClass( ve.ce.ContentBranchNode, ve.ce.BranchNode );
|
|||
*/
|
||||
ve.ce.ContentBranchNode.prototype.onChildUpdate = function ( transaction ) {
|
||||
var surfaceModel = this.getRoot().getSurface().getModel(),
|
||||
surfaceModelState = surfaceModel.getCompleteHistoryLength();
|
||||
surfaceModelState = surfaceModel.getDocument().getCompleteHistoryLength();
|
||||
|
||||
if ( transaction instanceof ve.dm.Transaction ) {
|
||||
if ( surfaceModelState === this.surfaceModelState ) {
|
||||
|
|
|
@ -45,6 +45,7 @@ ve.dm.Document = function VeDmDocument( documentOrData, parentDocument ) {
|
|||
|
||||
// Properties
|
||||
this.parentDocument = parentDocument;
|
||||
this.completeHistory = [];
|
||||
|
||||
if ( documentOrData instanceof ve.dm.LinearData ) {
|
||||
this.data = documentOrData;
|
||||
|
@ -222,6 +223,10 @@ ve.dm.Document.prototype.rollback = function ( transaction ) {
|
|||
throw new Error( 'Cannot roll back a transaction that has not been committed' );
|
||||
}
|
||||
new ve.dm.TransactionProcessor( this, transaction, true ).process();
|
||||
this.completeHistory.push( {
|
||||
'undo': true,
|
||||
'transaction': transaction
|
||||
} );
|
||||
this.emit( 'transact', transaction, true );
|
||||
};
|
||||
|
||||
|
@ -238,6 +243,10 @@ ve.dm.Document.prototype.commit = function ( transaction ) {
|
|||
throw new Error( 'Cannot commit a transaction that has already been committed' );
|
||||
}
|
||||
new ve.dm.TransactionProcessor( this, transaction, false ).process();
|
||||
this.completeHistory.push( {
|
||||
'undo': false,
|
||||
'transaction': transaction
|
||||
} );
|
||||
this.emit( 'transact', transaction, false );
|
||||
};
|
||||
|
||||
|
@ -867,3 +876,20 @@ ve.dm.Document.prototype.getSlice = function ( range ) {
|
|||
new ve.Range( addOpenings.length, addOpenings.length + range.getLength() )
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the length of the complete history stack. This is also the current pointer.
|
||||
* @returns {number} Length of the complete history stack
|
||||
*/
|
||||
ve.dm.Document.prototype.getCompleteHistoryLength = function () {
|
||||
return this.completeHistory.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all the items in the complete history stack since a specified pointer.
|
||||
* @param {number} pointer Pointer from where to start the slice
|
||||
* @returns {Array} Array of transaction objects with undo flag
|
||||
*/
|
||||
ve.dm.Document.prototype.getCompleteHistorySince = function ( pointer ) {
|
||||
return this.completeHistory.slice( pointer );
|
||||
};
|
||||
|
|
|
@ -25,7 +25,6 @@ ve.dm.Surface = function VeDmSurface( doc ) {
|
|||
this.selectedNodes = {};
|
||||
this.smallStack = [];
|
||||
this.bigStack = [];
|
||||
this.completeHistory = [];
|
||||
this.undoIndex = 0;
|
||||
this.historyTrackingInterval = null;
|
||||
this.insertionAnnotations = new ve.dm.AnnotationSet( this.documentModel.getStore() );
|
||||
|
@ -315,10 +314,6 @@ ve.dm.Surface.prototype.change = function ( transactions, selection ) {
|
|||
if ( !transactions[i].isNoOp() ) {
|
||||
this.truncateUndoStack();
|
||||
this.smallStack.push( transactions[i] );
|
||||
this.completeHistory.push( {
|
||||
'undo': false,
|
||||
'transaction': transactions[i]
|
||||
} );
|
||||
this.documentModel.commit( transactions[i] );
|
||||
}
|
||||
}
|
||||
|
@ -452,10 +447,6 @@ ve.dm.Surface.prototype.undo = function () {
|
|||
for ( i = item.stack.length - 1; i >= 0; i-- ) {
|
||||
transaction = item.stack[i];
|
||||
selection = transaction.translateRange( selection, true );
|
||||
this.completeHistory.push( {
|
||||
'undo': true,
|
||||
'transaction': transaction
|
||||
} );
|
||||
this.documentModel.rollback( transaction );
|
||||
}
|
||||
this.emit( 'unlock' );
|
||||
|
@ -465,23 +456,6 @@ ve.dm.Surface.prototype.undo = function () {
|
|||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the length of the complete history stack. This is also the current pointer.
|
||||
* @returns {number} Length of the complete history stack
|
||||
*/
|
||||
ve.dm.Surface.prototype.getCompleteHistoryLength = function () {
|
||||
return this.completeHistory.length;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get all the items in the complete history stack since a specified pointer.
|
||||
* @param {number} pointer Pointer from where to start the slice
|
||||
* @returns {Array} Array of transaction objects with undo flag
|
||||
*/
|
||||
ve.dm.Surface.prototype.getCompleteHistorySince = function ( pointer ) {
|
||||
return this.completeHistory.slice( pointer );
|
||||
};
|
||||
|
||||
/**
|
||||
* Step forwards in history.
|
||||
*
|
||||
|
@ -505,10 +479,6 @@ ve.dm.Surface.prototype.redo = function () {
|
|||
selection = item.selection;
|
||||
for ( i = 0; i < item.stack.length; i++ ) {
|
||||
transaction = item.stack[i];
|
||||
this.completeHistory.push( {
|
||||
'undo': false,
|
||||
'transaction': transaction
|
||||
} );
|
||||
this.documentModel.commit( transaction );
|
||||
}
|
||||
this.undoIndex--;
|
||||
|
|
|
@ -37,7 +37,7 @@ ve.dm.SurfaceFragment = function VeDmSurfaceFragment( surface, range, noAutoSele
|
|||
Math.min( Math.max( this.range.from, 0 ), length ),
|
||||
Math.min( Math.max( this.range.to, 0 ), length )
|
||||
);
|
||||
this.historyPointer = this.getSurface().getCompleteHistoryLength();
|
||||
this.historyPointer = this.document.getCompleteHistoryLength();
|
||||
};
|
||||
|
||||
/* Static Properties */
|
||||
|
@ -59,8 +59,8 @@ ve.dm.SurfaceFragment.static = {};
|
|||
ve.dm.SurfaceFragment.prototype.update = function () {
|
||||
var i, length, txs;
|
||||
// Small optimisation: check history pointer is in the past
|
||||
if ( this.historyPointer < this.getSurface().getCompleteHistoryLength() ) {
|
||||
txs = this.getSurface().getCompleteHistorySince( this.historyPointer );
|
||||
if ( this.historyPointer < this.document.getCompleteHistoryLength() ) {
|
||||
txs = this.document.getCompleteHistorySince( this.historyPointer );
|
||||
for ( i = 0, length = txs.length; i < length; i++ ) {
|
||||
this.range = txs[i].transaction.translateRange( this.range, txs[i].undo );
|
||||
this.historyPointer++;
|
||||
|
|
Loading…
Reference in a new issue