or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

bidi.mdbuiltin-extensions.mddecorations.mdeditor-view.mdextensions.mdgutters.mdindex.mdkeybindings.mdlayout.mdpanels.mdtooltips.md
tile.json

keybindings.mddocs/

Key Bindings

CodeMirror's key binding system provides flexible keyboard interaction support with platform-specific modifiers, multi-stroke keys, and contextual commands.

KeyBinding Interface

interface KeyBinding {
  key: string;
  run: Command;
  shift?: Command;
  scope?: string;
  preventDefault?: boolean;
}

Keymap Facet

const keymap: Facet<readonly KeyBinding[]>;

function runScopeHandlers(view: EditorView, event: KeyboardEvent, scope: string): boolean;

Usage Examples

Basic Key Bindings

import { keymap } from "@codemirror/view";

const basicKeys = keymap.of([
  { key: "Ctrl-s", run: saveCommand },
  { key: "Ctrl-z", run: undoCommand },
  { key: "Ctrl-y", run: redoCommand },
  { key: "Mod-a", run: selectAllCommand } // Ctrl on PC, Cmd on Mac
]);

Multi-stroke Key Bindings

const multiStrokeKeys = keymap.of([
  { key: "Ctrl-k Ctrl-c", run: commentCommand },
  { key: "Ctrl-k Ctrl-u", run: uncommentCommand }
]);

Conditional Commands

const conditionalKeys = keymap.of([
  {
    key: "Tab",
    run: (view) => {
      if (view.state.selection.ranges.some(r => !r.empty)) {
        return indentSelection(view);
      }
      return insertTab(view);
    }
  }
]);