@witchcraft/spellcraft
    Preparing search index...

    Interface Command<TName, TExec, TCondition>

    interface Command<
        TName extends string = string,
        TExec extends CommandExecute<string> = CommandExecute<string>,
        TCondition extends Condition = Condition,
    > {
        condition: TCondition;
        description: string;
        execute?: TExec;
        name: TName;
        type: "command";
    }

    Type Parameters

    Index

    Properties

    condition: TCondition

    Commands may have an additional condition that must be met, apart from the shortcut's that triggered it.

    If the command is created without a condition, it is assigned a blank condition. If you are using a custom condition class, you should probably always pass a blank condition.

    description: string

    A description of what the command does.

    execute?: TExec

    The function to execute when a shortcut triggers it's command. It is executed both on keydown and keyup (of the first released key) so be sure to check the isKeydown parameter so you don't trigger commands twice.

    The command itself is passed to it, and if it is managed by a manager it is also passed the shortcut, the manager itself, and the event of the last key that triggered it. Note the event might not exist when the manager needs to emulate a key release. See Manager.autoReleaseDelay.

    You should do e.preventDefault if you need it or haven't done so from Manager.eventFilter.

    You should also do safeSetManagerChain on keyup for most regular shortcuts. See it for details.

    See Manager.

    name: TName

    Unique string to identify the command by.

    Note that when changing a command's name, it is not an error for the old command to not exist in the manager. This is to allow for easier checking if a command can be added. If you need it to be an error, you can add a canSetCommand hook.

    type: "command"