All files / src/ui/commands ve.ui.HistoryCommand.js

80% Statements 8/10
50% Branches 2/4
50% Functions 1/2
80% Lines 8/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                1x 2x     2x   2x               1x             1x                   1x   1x  
/*!
 * VisualEditor UserInterface HistoryCommand class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * UserInterface history command.
 *
 * @class
 * @extends ve.ui.Command
 *
 * @constructor
 * @param {string} name
 * @param {string} [method]
 */
ve.ui.HistoryCommand = function VeUiHistoryCommand( name, method ) {
	method = method || name;
 
	// Parent constructor
	ve.ui.HistoryCommand.super.call( this, name, 'history', method );
 
	this.checkMethod = {
		undo: 'canUndo',
		redo: 'canRedo'
	}[ method ];
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.HistoryCommand, ve.ui.Command );
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.HistoryCommand.prototype.isExecutable = function ( fragment ) {
	const surface = fragment.getSurface();
 
	// Parent method
	return ve.ui.HistoryCommand.super.prototype.isExecutable.apply( this, arguments ) &&
		surface[ this.checkMethod ]();
};
 
/* Registration */
 
ve.ui.commandRegistry.register( new ve.ui.HistoryCommand( 'undo' ) );
 
ve.ui.commandRegistry.register( new ve.ui.HistoryCommand( 'redo' ) );