Skip to content

@jsvision/ui / buildKeymap

Function: buildKeymap()

buildKeymap(clipboardKeys?, userKeymap?): Keymap | undefined

Defined in: ui/src/event/default-keymap.ts:73

Build the loop's keymap: the framework's default clipboard bindings for clipboardKeys, with the caller's own keymap merged on top (the caller's bindings win on any conflicting chord).

The merge composes at lookup time rather than merging records: a compiled Keymap exposes only lookup, so the caller's chord table cannot be re-read — instead the returned keymap tries the caller's lookup first and falls back to the defaults. When clipboardKeys is 'none' there is no default layer, so the caller's keymap is returned as-is (or undefined when there is none).

Parameters

clipboardKeys?

ClipboardKeys = 'both'

Which clipboard key set to bind by default. Defaults to 'both'.

userKeymap?

Keymap

An optional app keymap whose bindings override the defaults.

Returns

Keymap | undefined

A compiled keymap, or undefined when there is nothing to bind ('none' and no user keymap).

Example

ts
import { createKeymap } from '@jsvision/core';
import { buildKeymap } from '@jsvision/ui';

const keymap = buildKeymap('modern', createKeymap({ 'ctrl+s': 'save' }));
keymap?.lookup({ type: 'key', key: 'c', ctrl: true, alt: false, shift: false }); // 'copy' (default)
keymap?.lookup({ type: 'key', key: 's', ctrl: true, alt: false, shift: false }); // 'save' (user)