Report an issue
Class

KeystrokeHandler (utils)

@ckeditor/ckeditor5-utils/src/keystrokehandler

class

Keystroke handler registers keystrokes so the callbacks associated with these keystrokes will be executed if the matching keydown is fired by a defined emitter.

const handler = new KeystrokeHandler();

handler.listenTo( emitter );

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

Filtering

Properties

  • _listener : Emitter

    protected

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

Methods

  • constructor()

    Creates an instance of the keystroke handler.

  • destroy()

    Destroys the keystroke handler.

  • listenTo( emitter )

    Starts listening for keydown events from a given emitter.

    Parameters

    emitter : Emitter
  • press( keyEvtData ) → Boolean

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

    Parameters

    keyEvtData : KeyEventData

    Key event data.

    Returns

    Boolean

    Whether the keystroke was handled.

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

    Registers a handler for the specified keystroke.

    Parameters

    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 to both preventDefault and stopPropagation of the event.

    [ options ] : Object

    Additional options.

    Properties
    [ 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 {}