KeystrokeHandler (utils)



Keystroke handler allows registering callbacks for given keystrokes.

The most frequent use of this class is through the editor.keystrokes property. It allows listening to keystrokes executed in the editing view:

editor.keystrokes.set( 'Ctrl+A', ( keyEvtData, cancel ) => {
	console.log( 'Ctrl+A has been pressed' );
} );

However, this utility class can be used in various part of the UI. For instance, a certain View can use it like this:

class MyView extends View {
	constructor() {
		this.keystrokes = new KeystrokeHandler();

		this.keystrokes.set( 'tab', handleTabKey );

	render() {

		this.keystrokes.listenTo( this.element );

That keystroke handler will listen to keydown events fired in this view's main element.



  • protected

    _listener : Emitter

    Listener used to listen to events for easier keystroke handler destruction.


  • constructor()

    Creates an instance of the keystroke handler.

  • destroy()

    Destroys the keystroke handler.

  • listenTo( emitter )

    Starts listening for keydown events from a given emitter.


    emitter : Emitter
  • press( keyEvtData ) → Boolean

    Triggers a keystroke handler for a specified key combination, if such a keystroke was defined.


    keyEvtData : KeyEventData

    Key event data.



    Whether the keystroke was handled.

  • set( keystroke, callback, [ options ] = { [options.priority] } )

    Registers a handler for the specified keystroke.


    keystroke : String | Array.<(String | Number)>

    Keystroke defined in a format accepted by the parseKeystroke function.

    callback : function

    A function called with the key event data object and a helper funcion to call both preventDefault() and stopPropagation() on the underlying event.

    [ options ] : Object

    Additional options.

    [ options.priority ] : PriorityString | Number

    The priority of the keystroke callback. The higher the priority value the sooner the callback will be executed. Keystrokes having the same priority are called in the order they were added.

    Defaults to 'normal'

    Defaults to {}