Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/keydownhandlers/ve.ce.LinearEscapeKeyDownHandler.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable linear escape key down handler
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /* istanbul ignore next */
8 /**
9 * Escape key down handler for linear selections.
10 *
11 * @class
12 * @extends ve.ce.KeyDownHandler
13 *
14 * @constructor
15 */
16 ve.ce.LinearEscapeKeyDownHandler = function VeCeLinearEscapeKeyDownHandler() {
17 // Parent constructor - never called because class is fully static
18 // ve.ui.LinearEscapeKeyDownHandler.super.apply( this, arguments );
19 };
20
21 /* Inheritance */
22
23 OO.inheritClass( ve.ce.LinearEscapeKeyDownHandler, ve.ce.KeyDownHandler );
24
25 /* Static properties */
26
27 ve.ce.LinearEscapeKeyDownHandler.static.name = 'linearEscape';
28
29 ve.ce.LinearEscapeKeyDownHandler.static.keys = [ OO.ui.Keys.ESCAPE ];
30
31 ve.ce.LinearEscapeKeyDownHandler.static.supportedSelections = [ 'linear' ];
32
33 /* Static methods */
34
35 /**
36 * Handle escape key down events with a linear selection while table editing.
37 *
38 * @inheritdoc
39 */
40 ve.ce.LinearEscapeKeyDownHandler.static.execute = function ( surface, e ) {
41 const activeTableNode = surface.getActiveNode() && surface.getActiveNode().findParent( ve.ce.TableNode );
42 if ( activeTableNode ) {
43 e.preventDefault();
44 e.stopPropagation();
45 activeTableNode.setEditing( false );
46 // If this was a merged cell, we're going to have unexpected behavior when the selection moves,
47 // so preemptively collapse to the top-left point of the merged cell.
48 surface.getModel().setSelection( surface.getModel().getSelection().collapseToStart() );
49 return true;
50 }
51 return false;
52 };
53
54 /* Registration */
55
56 ve.ce.keyDownHandlerFactory.register( ve.ce.LinearEscapeKeyDownHandler );