Trilium Frontend API
    Preparing search index...

    Class KeystrokeHandler

    Keystroke handler allows registering callbacks for given keystrokes.

    The most frequent use of this class is through the module:core/editor/editor~Editor#keystrokes 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' );
    cancel();
    } );

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

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

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

    render() {
    super.render();

    this.keystrokes.listenTo( this.element );
    }
    }

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

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates an instance of the keystroke handler.

      Returns KeystrokeHandler

    Methods

    • Destroys the keystroke handler.

      Returns void

    • Starts listening for keydown events from a given emitter.

      Parameters

      Returns void

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

      Parameters

      Returns boolean

      Whether the keystroke was handled.

    • Registers a handler for the specified keystroke.

      Parameters

      • keystroke: string | readonly (string | number)[]

        Keystroke defined in a format accepted by the module:utils/keyboard~parseKeystroke function.

      • callback: (ev: KeyboardEvent, cancel: () => void) => void

        A function called with the module:engine/view/observer/keyobserver~ViewDocumentKeyEventData key event data object and a helper function to call both preventDefault() and stopPropagation() on the underlying event.

      • Optionaloptions: KeystrokeHandlerOptions

        Additional options.

      Returns void

    • Stops listening to keydown events from the given emitter.

      Parameters

      Returns void