Skip to content

Base Keymap

BaseKeymap adds essential keyboard shortcuts for basic editing operations. It wraps ProseMirror’s baseKeymap which provides Enter, Backspace, Delete, Select All, and platform-specific Emacs-style shortcuts on macOS.

Included in StarterKit by default.

BaseKeymap is included in StarterKit, so it works out of the box. To use it standalone:

import { Editor, Document, Paragraph, Text, BaseKeymap } from '@domternal/core';
import '@domternal/theme';
const editor = new Editor({
element: document.getElementById('editor')!,
extensions: [Document, Paragraph, Text, BaseKeymap],
content: '<p>Try pressing Enter, Backspace, or Mod-A to select all.</p>',
});

To disable BaseKeymap in StarterKit:

StarterKit.configure({ baseKeymap: false })
OptionTypeDefaultDescription
enterbooleantrueWhether to include an explicit Enter key binding
import { BaseKeymap } from '@domternal/core';
// Disable the explicit Enter binding (uses ProseMirror's default Enter instead)
StarterKit.configure({
baseKeymap: { enter: false },
});

When enter is true (the default), BaseKeymap sets an explicit Enter binding that chains four ProseMirror commands in order:

  1. newlineInCode - inserts a newline character if the cursor is inside a code block
  2. createParagraphNear - creates a new paragraph adjacent to the current block if the cursor is at an edge
  3. liftEmptyBlock - lifts an empty block out of its parent (e.g., pressing Enter in an empty blockquote exits the blockquote)
  4. splitBlock - splits the current block at the cursor position (the standard paragraph-splitting behavior)

The chain tries each command in sequence and stops at the first one that succeeds.

When enter is false, the Enter binding from ProseMirror’s built-in baseKeymap is used as-is. Currently both produce the same chain of commands, but having an explicit binding allows Domternal to customize the Enter behavior independently in future versions.

BaseKeymap does not register any editor commands. All key bindings are applied directly via a ProseMirror keymap plugin.

KeyCommandDescription
EnterChained enterInsert newline in code, create paragraph near, lift empty block, or split block
Mod-EnterexitCodeExit a code block and create a paragraph after it
BackspacebackspaceDelete backward
Mod-BackspacebackspaceDelete backward
Shift-BackspacebackspaceDelete backward
DeletedelDelete forward
Mod-DeletedelDelete forward
Mod-aselectAllSelect all content in the editor

Mod is Cmd on macOS and Ctrl on Windows/Linux.

On macOS and iOS, ProseMirror’s baseKeymap includes additional bindings that map Emacs-style shortcuts to editing commands:

KeyCommandDescription
Ctrl-hbackspaceDelete backward (Emacs)
Alt-BackspacebackspaceDelete backward
Ctrl-ddelDelete forward (Emacs)
Ctrl-Alt-BackspacedelDelete forward
Alt-DeletedelDelete forward
Alt-ddelDelete forward (Emacs)
Ctrl-aselectTextblockStartMove cursor to start of text block
Ctrl-eselectTextblockEndMove cursor to end of text block

BaseKeymap does not register any input rules.

BaseKeymap does not register any toolbar items.

BaseKeymap creates a ProseMirror keymap plugin by spreading ProseMirror’s baseKeymap object (which is platform-aware) and optionally overriding the Enter key binding:

addProseMirrorPlugins() {
const bindings = { ...baseKeymap };
if (this.options.enter) {
bindings['Enter'] = chainCommands(
newlineInCode,
createParagraphNear,
liftEmptyBlock,
splitBlock
);
}
return [keymap(bindings)];
}

ProseMirror automatically detects the platform and uses either pcBaseKeymap (Windows/Linux) or macBaseKeymap (macOS/iOS), which includes the additional Emacs-style shortcuts listed above.

import { BaseKeymap } from '@domternal/core';
import type { BaseKeymapOptions } from '@domternal/core';
ExportTypeDescription
BaseKeymapExtensionThe base keymap extension
BaseKeymapOptionsTypeScript typeOptions for BaseKeymap.configure()

@domternal/core - BaseKeymap.ts