Search Docs
Loading...
Skip to content

Class: ShortcutsAPI

engine.shortcuts — a remappable map of keyboard shortcuts to actions.

Each shortcut maps a chord (e.g. Mod+z, Shift+ArrowUp) to a run (an action id run via engine.actions.run, or an inline function), plus a scope (the UI scopes it is restricted to) and an optional when gate. This web layer owns the key map and the listener; the C++ engine stays input-agnostic.

The API is engine-only: when/run receive { engine }. Scope is filtered by the dispatcher (via each shortcut’s scope), not the predicate. A host that needs richer state (the web editor’s cesdk.ui.shortcuts) closes over it in the predicates it registers — the engine never sees it.

Remarks#

Browser-only. The editor mounts it on its container automatically.

Constructors#

Constructor#


ShortcutsAPI

Methods#

set()#


Register one keyboard shortcut, or many at once. A shortcut’s identity is its keys+scope: registering that combination again replaces it.

Parameters#

ParameterTypeDescription
shortcutShortcut

Returns#

A disposer that removes everything this call registered.

() => void

Signature#

set(shortcut: Shortcut | Shortcut[]): () => void

remove()#


Remove every shortcut matching options (keys AND scopes, glob-matched). Both fields are required and must be non-empty; use ’*’ to match all (e.g. { keys: ‘Mod+s’, scopes: ’*’ }). Throws on an empty keys/scopes.

Parameters#

ParameterType
options{ keys: string
options.keysstring
options.scopes

Returns#

void

Signature#

remove(options: object): void

has()#


Whether a shortcut is bound to the given key combo or sequence.

Parameters#

ParameterType
keysstring

Returns#

boolean

Signature#

has(keys: string | string[]): boolean

get()#


Get the first shortcut matching options, or undefined. See list for the matching rules.

Parameters#

ParameterType
options{ keys: string
options.keysstring
options.scopes

Returns#

Shortcut

Signature#

get(options: object): Shortcut

list()#


List the shortcuts whose scope matches options.scopes (glob-matched). scopes is required and must be non-empty; { scopes: ’*’ } lists everything. Throws on an empty scopes. To find a rule by chord use get/has.

Parameters#

ParameterType
options{ scopes:
options.scopes

Returns#

Shortcut[]

Signature#

list(options: object): Shortcut[]

clear()#


Remove every registered shortcut. Scopes and the listener are untouched.

Returns#

void

Signature#

clear(): void

setEnabled()#


Enable or disable the whole keyboard layer.

Parameters#

ParameterType
enabledboolean

Returns#

void

Signature#

setEnabled(enabled: boolean): void

addScope()#


Register a UI scope id the dispatcher should recognise while resolving the active scope. Hosts stamp data-shortcut-scope=“<id>” on the matching DOM surface; the walk returns the nearest such ancestor’s id.

Parameters#

ParameterType
idShortcutScopeId

Returns#

A disposer that unregisters this scope id.

() => void

Signature#

addScope(id: ShortcutScopeId): () => void

setRoot()#


Set the DOM root the keyboard layer binds to: the capture-phase keydown listener is attached to target, and scope resolution walks up to it. Defaults to the engine canvas, so a headless integration is scoped out of the box and never swallows the host app’s keys. A host UI passes its editor container to widen coverage.

Calling it again re-binds onto the new target — this is how you change the root. Returns a disposer that stops listening.

Parameters#

ParameterType
target?ShortcutRoot

Returns#

() => void

Signature#

setRoot(target?: ShortcutRoot): () => void