> ## Documentation Index
> Fetch the complete documentation index at: https://docs.reducto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Keyboard shortcuts

Commands, key bindings and where the user's changes live. Guide: [Keyboard shortcuts](https://docs.reducto.ai/office/docx/ui/keyboard-shortcuts.md).

## `Keymap`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`. Extends [`Observable`](https://docs.reducto.ai/office/docx/api/editor-panels#observable).

### Keymap properties

| Name | Type | Description |
| - | - | - |
| `pending` | `string \| null` | The first press of a chord, waiting for the second. |
| `platform` | `Platform` | read-only |
| `revision` | `number` | Bumps when commands, overrides or contexts change. |
| `user` | `readonly Keybinding[]` | The user's changes, as stored. |
| `version` | `number` | Bumps on every change of this object or an adopted child. |

### `allCommands()`

```ts theme={null}
allCommands(): KeyCommand<Ctx>[]
```

Every registered command, in registration order.

### `bind()`

```ts theme={null}
bind(binding: Keybinding): void
```

Adds a user binding. Throws on a key the user cannot take.

### `cancelChord()`

```ts theme={null}
cancelChord(): void
```

Abandons a chord's first press.

### `chain()`

```ts theme={null}
chain(key: string): string[]
```

Every command a key reaches now, the one that runs first; later ones run when it declines.

### `command()`

```ts theme={null}
command(id: string): KeyCommand<Ctx> | undefined
```

### `conflicts()`

```ts theme={null}
conflicts(key: string, when?: string): string[]
```

Commands a key already reaches under the same `when` (both none counts as the same).

### `destroy()`

```ts theme={null}
destroy(): void
```

### `enabled()`

```ts theme={null}
enabled(id: string): boolean
```

### `exportJson()`

```ts theme={null}
exportJson(): string
```

The user's changes as a file.

### `handle()`

```ts theme={null}
handle(event: KeyEventLike & { isComposing?: boolean }): boolean
```

Runs the command a press is bound to; true when one took it (the caller prevents the default).

### `importJson()`

```ts theme={null}
importJson(text: string): void
```

Replaces the user's changes with a file from `exportJson`. Throws on a bad file.

### `keysFor()`

```ts theme={null}
keysFor(id: string): string[]
```

Normalized keys of a command, visible ones only.

### `label()`

```ts theme={null}
label(idOrKey: string): string
```

The label of a command's first key ("⌘B"), or of a key spec; "" when unbound.

### `list()`

```ts theme={null}
list(): CommandInfo[]
```

### `observes()`

```ts theme={null}
observes(key: string): boolean
```

### `refusal()`

```ts theme={null}
refusal(key: string): string | undefined
```

Why the user cannot take a key, or undefined.

### `register()`

```ts theme={null}
register(command: KeyCommand<Ctx>): () => void
```

Adds a command, or replaces the one with its id (until the returned function runs).

### `replace()`

```ts theme={null}
replace(id: string, key: string, when?: string): void
```

The Keyboard Shortcuts window's edit: the command's keys become `key` alone, and any
command the key reached under the same `when` gives it up.

### `reset()`

```ts theme={null}
reset(id?: string): void
```

Back to the defaults (and the host's overrides): one command, or all.

### `resolve()`

```ts theme={null}
resolve(key: string): string | undefined
```

The command a key reaches in these contexts, without running it.

### `run()`

```ts theme={null}
run(id: string, args?: unknown): boolean
```

Runs a command by id, as a palette row or a host button would.

### `setContext()`

```ts theme={null}
setContext(name: string, value: boolean): void
```

### `setOverrides()`

```ts theme={null}
setOverrides(overrides: readonly Keybinding[]): void
```

Host bindings between the defaults and the user's changes.

### `stampOf()`

```ts theme={null}
stampOf(key: string): number
```

### `subscribe()`

```ts theme={null}
subscribe(listener: Listener, key?: string): Unsubscribe
```

Listen to one key, or to every change (including adopted children) when `key` is omitted.

### `title()`

```ts theme={null}
title(id: string, text?: string): string
```

"Bold (⌘B)", for a tooltip.

### `unbind()`

```ts theme={null}
unbind(id: string, key?: string): void
```

Removes a command's keys, or one of them.

## `createDocxKeymap()`

```ts theme={null}
function createDocxKeymap(model: EditorModel, options?: KeybindingOptions): DocxKeymap
```

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `KeybindingOptions`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

| Name | Type | Description |
| - | - | - |
| `customizable?` | `boolean` | False hides the Keyboard Shortcuts window and its menu entries. Default true. |
| `overrides?` | `Keybinding[]` | Added after Word's defaults and before the user's changes. |
| `platform?` | `Platform` | Default: the platform the browser reports. |
| `store?` | `KeybindingStore \| null` | Where the user's changes live. Default: `localStorage` under "docx-editor:keybindings"; null keeps them for the page only. |

## `Keybinding`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

| Name | Type | Description |
| - | - | - |
| `args?` | `unknown` | |
| `command` | `string` | "-format.bold" removes the earlier bindings of that command (of `key` only, when given). |
| `hidden?` | `boolean` | Works, but is not shown or offered as the command's key. |
| `key?` | `string` | "mod+shift+k"; a chord is two presses: "mod+k mod+c". |
| `platform?` | `Platform` | |
| `when?` | `string` | |

## `KeyCommand`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

| Name | Type | Description |
| - | - | - |
| `category` | `string` | |
| `id` | `string` | Stable, public: `format.bold`, `cursor.wordLeft.select`. |
| `keywords?` | `string[]` | |
| `palette?` | `boolean` | False keeps the command out of the command palette (caret moves, deletes). |
| `title` | `string` | |
| `enabled()?` | `(ctx: Ctx) => boolean` | False greys the command and lets its keys fall through. |
| `run()` | `(ctx: Ctx, args?: unknown) => boolean \| void` | False: not handled here, so the next binding of the key (or the browser) gets it. |

## `CommandInfo`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

| Name | Type | Description |
| - | - | - |
| `category` | `string` | |
| `id` | `string` | |
| `keys` | `string[]` | Normalized keys now bound, in the order they were bound. |
| `source` | `BindingSource` | |
| `title` | `string` | |
| `whens` | `(string \| undefined)[]` | The `when` of each key, in the same order. |

## `BindingSource`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

```ts theme={null}
type BindingSource = "default" | "app" | "user"
```

## `KeybindingStore`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

| Name | Type | Description |
| - | - | - |
| `load()` | `() => UserKeybindings \| Promise<UserKeybindings \| null> \| null` | |
| `save()` | `(value: UserKeybindings) => void \| Promise<void>` | |
| `subscribe()?` | `(listener: (value: UserKeybindings \| null) => void) => () => void` | Changes made elsewhere: another tab, another device. |

## `UserKeybindings`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

| Name | Type | Description |
| - | - | - |
| `bindings` | `Keybinding[]` | |
| `version` | `1` | |

## `localStorageKeybindings()`

```ts theme={null}
function localStorageKeybindings(key: string): KeybindingStore
```

One `localStorage` row per app; other tabs of the same origin follow a change.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `memoryKeybindings()`

```ts theme={null}
function memoryKeybindings(initial?: UserKeybindings | null): KeybindingStore
```

Keeps the changes for the life of the page.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `DOCX_KEYBINDINGS`

```ts theme={null}
const DOCX_KEYBINDINGS: readonly Keybinding[] = ...
```

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `PALETTE_ON_MOD_K`

```ts theme={null}
const PALETTE_ON_MOD_K: Keybinding = ...
```

⌘K (Ctrl+K) for the palette, as our apps bind it; Word's Insert Link keeps its menu entries.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `routePalette()`

```ts theme={null}
function routePalette(model: EditorModel, toggle: () => void): () => void
```

`palette.open` toggles the host's own palette instead of the built-in one.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `KEYBINDINGS_STORAGE_KEY`

```ts theme={null}
const KEYBINDINGS_STORAGE_KEY: "docx-editor:keybindings" = "docx-editor:keybindings"
```

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.
