Core framework for building cloud and desktop IDE applications using modern web technologies with TypeScript and dependency injection.
—
Theia's keybinding system provides comprehensive key combination handling with context awareness, command integration, and platform-specific key mapping for accessible applications.
Define key combinations that trigger commands.
/**
* Keybinding definition
*/
interface Keybinding {
/** Key combination string (e.g., 'ctrl+s', 'cmd+shift+p') */
keybinding: string;
/** Command to execute */
command: string;
/** Optional context expression */
context?: string;
/** Optional arguments to pass to command */
args?: any[];
/** When clause for conditional activation */
when?: string;
}Central registry for managing keybindings and key event handling.
/**
* Registry for keybindings
*/
interface KeybindingRegistry {
/**
* Register a keybinding
* @param binding - Keybinding definition
* @returns Disposable to unregister
*/
registerKeybinding(binding: Keybinding): Disposable;
/**
* Get keybindings for command
* @param commandId - Command identifier
* @returns Array of keybindings
*/
getKeybindingsForCommand(commandId: string): Keybinding[];
/**
* Get all keybindings
* @returns Array of all registered keybindings
*/
getKeybindings(): Keybinding[];
/**
* Handle key event
* @param event - Keyboard event
* @returns True if event was handled
*/
run(event: KeyboardEvent): boolean;
}
/**
* Service token for KeybindingRegistry
*/
const KeybindingRegistry: symbol;Usage Example:
import { inject, injectable } from "@theia/core";
import { KeybindingRegistry, Keybinding } from "@theia/core/lib/browser";
@injectable()
export class MyKeybindingContribution {
constructor(
@inject(KeybindingRegistry)
private readonly keybindings: KeybindingRegistry
) {}
registerKeybindings(): void {
// Simple keybinding
this.keybindings.registerKeybinding({
keybinding: 'ctrl+alt+t',
command: 'my-extension.toggle-feature'
});
// Context-aware keybinding
this.keybindings.registerKeybinding({
keybinding: 'f2',
command: 'my-extension.rename',
when: 'editorFocus && !readonly'
});
// Keybinding with arguments
this.keybindings.registerKeybinding({
keybinding: 'ctrl+1',
command: 'workbench.action.openEditorAtIndex',
args: [0]
});
}
}Extension point for contributing keybindings.
/**
* Contribution interface for keybindings
*/
interface KeybindingContribution {
/**
* Register keybindings
* @param keybindings - Keybinding registry
*/
registerKeybindings(keybindings: KeybindingRegistry): void;
}
/**
* Service token for KeybindingContribution
*/
const KeybindingContribution: symbol;Advanced key sequence and chord support.
/**
* Key sequence for multi-key combinations
*/
interface KeySequence {
/** Array of key combinations */
sequence: string[];
/** Command to execute */
command: string;
/** Optional context */
context?: string;
}
/**
* Chord keybinding (multi-step key sequence)
*/
interface ChordKeybinding extends Keybinding {
/** First key combination */
firstPart: string;
/** Second key combination */
chordPart: string;
}type KeyCode = string;
type KeyModifier = 'ctrl' | 'cmd' | 'alt' | 'shift' | 'meta';
interface KeybindingContext {
[key: string]: any;
}Install with Tessl CLI
npx tessl i tessl/npm-theia--core