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
ShortcutsAPIMethods#
set()#
Register one keyboard shortcut, or many at once. A shortcut’s identity is
its keys+scope: registering that combination again replaces it.
keys+scope: registering that combination again replaces it.Parameters#
| Parameter | Type | Description |
|---|---|---|
shortcut | Shortcut |
Returns#
A disposer that removes everything this call registered.
() => void
Signature#
set(shortcut: Shortcut | Shortcut[]): () => voidremove()#
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.
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#
| Parameter | Type |
|---|---|
options | { keys: string |
options.keys | string |
options.scopes |
Returns#
void
Signature#
remove(options: object): voidhas()#
Whether a shortcut is bound to the given key combo or sequence.
Parameters#
| Parameter | Type |
|---|---|
keys | string |
Returns#
boolean
Signature#
has(keys: string | string[]): booleanget()#
Get the first shortcut matching options, or undefined. See list for the
matching rules.
options, or undefined. See list for the
matching rules.Parameters#
| Parameter | Type |
|---|---|
options | { keys: string |
options.keys | string |
options.scopes |
Returns#
ShortcutSignature#
get(options: object): Shortcutlist()#
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.
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#
| Parameter | Type |
|---|---|
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(): voidsetEnabled()#
Enable or disable the whole keyboard layer.
Parameters#
| Parameter | Type |
|---|---|
enabled | boolean |
Returns#
void
Signature#
setEnabled(enabled: boolean): voidaddScope()#
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.
data-shortcut-scope=“<id>” on the matching DOM
surface; the walk returns the nearest such ancestor’s id.Parameters#
| Parameter | Type |
|---|---|
id | ShortcutScopeId |
Returns#
A disposer that unregisters this scope id.
() => void
Signature#
addScope(id: ShortcutScopeId): () => voidsetRoot()#
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.
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#
| Parameter | Type |
|---|---|
target? | ShortcutRoot |
Returns#
() => void
Signature#
setRoot(target?: ShortcutRoot): () => void