all files / src/ce/keydownhandlers/ ve.ce.LinearEscapeKeyDownHandler.js

100% Statements 15/15
100% Branches 4/4
100% Functions 2/2
100% Lines 15/15
1 function Ignored     
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 52 53 54 55 56 57                                                                                   
/*!
 * VisualEditor ContentEditable linear escape key down handler
 *
 * @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/* istanbul ignore next */
/**
 * Escape key down handler for linear selections.
 *
 * @class
 * @extends ve.ce.KeyDownHandler
 *
 * @constructor
 */
ve.ce.LinearEscapeKeyDownHandler = function VeCeLinearEscapeKeyDownHandler() {
	// Parent constructor - never called because class is fully static
	// ve.ui.LinearEscapeKeyDownHandler.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ce.LinearEscapeKeyDownHandler, ve.ce.KeyDownHandler );
 
/* Static properties */
 
ve.ce.LinearEscapeKeyDownHandler.static.name = 'linearEscape';
 
ve.ce.LinearEscapeKeyDownHandler.static.keys = [ OO.ui.Keys.ESCAPE ];
 
ve.ce.LinearEscapeKeyDownHandler.static.supportedSelections = [ 'linear' ];
 
/* Static methods */
 
/**
 * @inheritdoc
 *
 * Handle escape key down events with a linear selection while table editing.
 */
ve.ce.LinearEscapeKeyDownHandler.static.execute = function ( surface, e ) {
	var activeTableNode = surface.getActiveNode() && surface.getActiveNode().findParent( ve.ce.TableNode );
	if ( activeTableNode ) {
		e.preventDefault();
		e.stopPropagation();
		activeTableNode.setEditing( false );
		// If this was a merged cell, we're going to have unexpected behavior when the selection moves,
		// so preemptively collapse to the top-left point of the merged cell.
		surface.getModel().setSelection( surface.getModel().getSelection().collapseToStart() );
		return true;
	}
	return false;
};
 
/* Registration */
 
ve.ce.keyDownHandlerFactory.register( ve.ce.LinearEscapeKeyDownHandler );