Skip to main content

Class: default

Defined in: src/lib/classes/ShortcutSettings/index.ts:37

The user's keyboard shortcuts: the key combination of each configurable action (see CONFIGURABLE_SHORTCUTS), each used by one action at most. Kept in memory; the implementer saves and restores them (see load and the change event).

Dispatches a change event when a key combination changes.

Example​

const shortcuts = new ShortcutSettings();
shortcuts.set("tool-brush", { key: "p" });
shortcuts.combo("tool-brush"); // { key: "p" }

Extends​

  • EventTarget

Constructors​

Constructor​

new default(initial?): ShortcutSettings

Defined in: src/lib/classes/ShortcutSettings/index.ts:42

Parameters​

initial?​

unknown

Returns​

ShortcutSettings

Overrides​

EventTarget.constructor

Accessors​

bindings​

Get Signature​

get bindings(): Readonly<ShortcutBindings>

Defined in: src/lib/classes/ShortcutSettings/index.ts:49

Each configurable action's key combination, by ID (read-only copy)

Returns​

Readonly<ShortcutBindings>


holdToPan​

Get Signature​

get holdToPan(): KeyCombo | null

Defined in: src/lib/classes/ShortcutSettings/index.ts:59

The key held to pan, returning to the last tool when released (null when it has none)

Returns​

KeyCombo | null


shortcuts​

Get Signature​

get shortcuts(): readonly Shortcut[]

Defined in: src/lib/classes/ShortcutSettings/index.ts:54

The shortcuts key presses are matched against (except the hold-to-pan key)

Returns​

readonly Shortcut[]

Methods​

addEventListener()​

addEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14380

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | AddEventListenerOptions

Returns​

void

Inherited from​

EventTarget.addEventListener


combo()​

combo(id): KeyCombo | null

Defined in: src/lib/classes/ShortcutSettings/index.ts:69

A configurable action's key combination (null when it has none or there's no such action).

Parameters​

id​

string

Returns​

KeyCombo | null

Example​

shortcuts.combo("deselect"); // { key: "d", cmd: true }

dispatchEvent()​

dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14386

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

MDN Reference

Parameters​

event​

Event

Returns​

boolean

Inherited from​

EventTarget.dispatchEvent


load()​

load(input): void

Defined in: src/lib/classes/ShortcutSettings/index.ts:120

Replace the key combinations, e.g. with saved or imported ones (see sanitiseShortcutBindings; actions left out get their defaults), and dispatch change if anything changed.

Parameters​

input​

unknown

Returns​

void

Example​

shortcuts.load({ "tool-brush": { key: "p" } });

removeEventListener()​

removeEventListener(type, callback, options?): void

Defined in: node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.dom.d.ts:14392

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

MDN Reference

Parameters​

type​

string

callback​

EventListenerOrEventListenerObject | null

options?​

boolean | EventListenerOptions

Returns​

void

Inherited from​

EventTarget.removeEventListener


reset()​

reset(): void

Defined in: src/lib/classes/ShortcutSettings/index.ts:109

Go back to the default key combinations.

Returns​

void


set()​

set(id, combo): ShortcutChangeResult

Defined in: src/lib/classes/ShortcutSettings/index.ts:81

Set or remove (null) a configurable action's key combination. If another configurable action has it, that action loses it (movedFrom). Nothing changes for a key combination a fixed action uses (fixed), or an unknown action.

Parameters​

id​

string

combo​

KeyCombo | null

Returns​

ShortcutChangeResult

Example​

shortcuts.set("tool-brush", { key: "e" }); // { changed: true, movedFrom: "tool-eraser" }
shortcuts.set("deselect", { key: "z", cmd: true }); // { changed: false, fixed: "undo" }