2012-10-24 21:34:01 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor HistoryAction class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* History action.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.Action}
|
|
|
|
* @param {ve.Surface} surface Surface to act on
|
|
|
|
*/
|
|
|
|
ve.HistoryAction = function VeHistoryAction( surface ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.Action.call( this, surface );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.HistoryAction, ve.Action );
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of allowed methods for this action.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.HistoryAction.static.methods = ['undo', 'redo'];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Steps backwards in time.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.HistoryAction.prototype.undo = function () {
|
2012-12-05 21:51:04 +00:00
|
|
|
var range = this.surface.getModel().undo();
|
2012-12-12 20:07:02 +00:00
|
|
|
if ( range ) {
|
|
|
|
this.surface.getView().showSelection( range );
|
|
|
|
}
|
2012-10-24 21:34:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Steps forwards in time.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.HistoryAction.prototype.redo = function () {
|
2012-12-05 21:51:04 +00:00
|
|
|
var range = this.surface.getModel().redo();
|
2012-12-12 20:07:02 +00:00
|
|
|
if ( range ) {
|
|
|
|
this.surface.getView().showSelection( range );
|
|
|
|
}
|
2012-10-24 21:34:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.actionFactory.register( 'history', ve.HistoryAction );
|