CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-theia--core

Core framework for building cloud and desktop IDE applications using modern web technologies with TypeScript and dependency injection.

Pending
Overview
Eval results
Files

keybindings.mddocs/

Keybindings

Theia's keybinding system provides comprehensive key combination handling with context awareness, command integration, and platform-specific key mapping for accessible applications.

Capabilities

Keybinding Definition

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;
}

Keybinding Registry

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]
        });
    }
}

Keybinding Contribution

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;

Key Sequences

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;
}

Types

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

docs

application-framework.md

commands.md

dependency-injection.md

events-messaging.md

index.md

keybindings.md

menus.md

preferences-configuration.md

resources-files.md

widgets-ui.md

tile.json