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>',});import { Component, signal } from '@angular/core';import { DomternalEditorComponent } from '@domternal/angular';import { Editor, Document, Paragraph, Text, BaseKeymap } from '@domternal/core';
@Component({ selector: 'app-editor', imports: [DomternalEditorComponent], templateUrl: './editor.html',})export class EditorComponent { editor = signal<Editor | null>(null); extensions = [Document, Paragraph, Text, BaseKeymap]; content = '<p>Try pressing Enter, Backspace, or Mod-A to select all.</p>';}<domternal-editor [extensions]="extensions" [content]="content" (editorCreated)="editor.set($event)"/>import { Domternal } from '@domternal/react';import { Document, Paragraph, Text, BaseKeymap } from '@domternal/core';
export default function Editor() { return ( <Domternal extensions={[Document, Paragraph, Text, BaseKeymap]} content="<p>Try pressing Enter, Backspace, or Mod-A to select all.</p>" > <Domternal.Content /> </Domternal> );}import { Editor, Document, Paragraph, Text, BaseKeymap } from '@domternal/core';
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 })Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
enter | boolean | true | Whether 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:
newlineInCode- inserts a newline character if the cursor is inside a code blockcreateParagraphNear- creates a new paragraph adjacent to the current block if the cursor is at an edgeliftEmptyBlock- lifts an empty block out of its parent (e.g., pressing Enter in an empty blockquote exits the blockquote)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.
Commands
Section titled “Commands”BaseKeymap does not register any editor commands. All key bindings are applied directly via a ProseMirror keymap plugin.
Keyboard shortcuts
Section titled “Keyboard shortcuts”All platforms
Section titled “All platforms”| Key | Command | Description |
|---|---|---|
Enter | Chained enter | Insert newline in code, create paragraph near, lift empty block, or split block |
Mod-Enter | exitCode | Exit a code block and create a paragraph after it |
Backspace | backspace | Delete backward |
Mod-Backspace | backspace | Delete backward |
Shift-Backspace | backspace | Delete backward |
Delete | del | Delete forward |
Mod-Delete | del | Delete forward |
Mod-a | selectAll | Select all content in the editor |
Mod is Cmd on macOS and Ctrl on Windows/Linux.
macOS only
Section titled “macOS only”On macOS and iOS, ProseMirror’s baseKeymap includes additional bindings that map Emacs-style shortcuts to editing commands:
| Key | Command | Description |
|---|---|---|
Ctrl-h | backspace | Delete backward (Emacs) |
Alt-Backspace | backspace | Delete backward |
Ctrl-d | del | Delete forward (Emacs) |
Ctrl-Alt-Backspace | del | Delete forward |
Alt-Delete | del | Delete forward |
Alt-d | del | Delete forward (Emacs) |
Ctrl-a | selectTextblockStart | Move cursor to start of text block |
Ctrl-e | selectTextblockEnd | Move cursor to end of text block |
Input rules
Section titled “Input rules”BaseKeymap does not register any input rules.
Toolbar items
Section titled “Toolbar items”BaseKeymap does not register any toolbar items.
How it works
Section titled “How it works”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.
Exports
Section titled “Exports”import { BaseKeymap } from '@domternal/core';import type { BaseKeymapOptions } from '@domternal/core';| Export | Type | Description |
|---|---|---|
BaseKeymap | Extension | The base keymap extension |
BaseKeymapOptions | TypeScript type | Options for BaseKeymap.configure() |
Source
Section titled “Source”@domternal/core - BaseKeymap.ts