UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

104 lines • 6.4 kB
import type { IKeyboardLayoutInfo, ILinuxKeyMapping, IMacKeyMapping } from 'native-keymap'; import { NativeKeyboardLayout, KeyboardLayoutProvider, KeyboardLayoutChangeNotifier, KeyValidator } from '../../common/keyboard/keyboard-layout-provider.js'; import { Emitter, Event } from '../../common/event.js'; import { KeyCode, Key, LayoutModifiers, NormalizedKeyboardInput } from './keys.js'; /** * A physical key and keyboard-layout modifier layer that can produce a logical character. */ export interface KeyboardLayoutCandidate { readonly key: Key; readonly character: string; readonly layoutModifiers: LayoutModifiers; } export interface KeyboardLayout { readonly candidatesByCharacter: ReadonlyMap<string, readonly KeyboardLayoutCandidate[]>; readonly candidatesByFoldedCharacter: ReadonlyMap<string, readonly KeyboardLayoutCandidate[]>; /** Physical KeyboardEvent code to the lowercase Latin letter registered as a fallback. */ readonly latinFallbackByCode: ReadonlyMap<string, string>; /** * Mapping of KeyboardEvent codes to the characters shown on the user's keyboard * for the respective keys. */ readonly code2Character: { [code: string]: string; }; } export declare class KeyboardLayoutService { protected readonly layoutProvider: KeyboardLayoutProvider; protected readonly layoutChangeNotifier: KeyboardLayoutChangeNotifier; protected readonly keyValidator?: KeyValidator; protected currentLayout?: KeyboardLayout; protected currentNativeLayout?: NativeKeyboardLayout; protected currentLayoutInfo?: IKeyboardLayoutInfo; get layoutInfo(): IKeyboardLayoutInfo | undefined; get layoutSource(): string; protected updateLayout(newLayout: NativeKeyboardLayout): KeyboardLayout; protected keyboardLayoutChanged: Emitter<KeyboardLayout>; get onKeyboardLayoutChanged(): Event<KeyboardLayout>; initialize(): Promise<void>; /** * Resolve an authored keybinding stroke against the active layout. * Physical and non-printable strokes, and strokes resolved without an active layout, are returned unchanged. Latin letters * missing from the active layout resolve to their US key position; any other missing logical character is returned with * {@link KeyCode.supportedByLayout} set to `false`. Authored Shift is absorbed when it produces the character (US-key tokens * or shift-layer candidates); otherwise it remains a command modifier. */ resolveKeyCode(inCode: KeyCode): KeyCode; /** * Whether the platform's AltGraph layer is active: AltGraph on Linux, Option on macOS, and AltGraph or Ctrl+Alt on Windows. */ protected isAltGraphActive(input: NormalizedKeyboardInput): boolean; /** * Detect the keyboard-layout modifier layer that produced an input character. * `undefined` means either that no layout modifiers were needed or that the input represents a dead key. */ detectLayoutModifiers(input: NormalizedKeyboardInput): LayoutModifiers | undefined; protected getNativeMapping(code: string): (ILinuxKeyMapping & Partial<IMacKeyMapping>) | undefined; /** * Return the character committed by the detected layout layer, which can differ from the input by case, e.g. because * Caps Lock inverted the case of the produced character. Returns `undefined` when the layer character is unknown. */ protected layerCharacter(input: NormalizedKeyboardInput, layoutModifiers: LayoutModifiers | undefined): string | undefined; /** * Return all command- and layout-modifier interpretations of a normalized keyboard input. * The committed character follows the detected layout layer, so Caps Lock does not change the case of the character. */ getKeyCodeInterpretations(input: NormalizedKeyboardInput, eventDispatch: 'code' | 'keyCode'): KeyCode[]; protected getLinuxKeyCodeInterpretations(keyCode: KeyCode, input: NormalizedKeyboardInput, layoutModifiers: LayoutModifiers | undefined): KeyCode[]; protected getWindowsKeyCodeInterpretations(keyCode: KeyCode, input: NormalizedKeyboardInput, layoutModifiers: LayoutModifiers | undefined): KeyCode[]; /** * macOS has no AltGraph key: Option selects the layout's AltGraph layer but is also the `alt` command modifier used by * the default macOS bindings. Option layers therefore yield interpretations that keep Option as a command modifier and * carry the character the key produces without Option, followed by the interpretation that attributes Option to the layout. */ protected getMacKeyCodeInterpretations(keyCode: KeyCode, input: NormalizedKeyboardInput, layoutModifiers: LayoutModifiers | undefined): KeyCode[]; /** Interpret Shift either as a command modifier or as part of the keyboard layout. */ protected shiftLayerInterpretations(keyCode: KeyCode, layoutModifiers: LayoutModifiers): KeyCode[]; protected toLayoutModifiersKeyCode(keyCode: KeyCode, layoutModifiers: LayoutModifiers, consumed?: { ctrl?: boolean; alt?: boolean; }): KeyCode; /** * Return the character shown on the user's keyboard for the given key. * Use this to determine UI representations of keybindings. */ getKeyboardCharacter(key: Key): string; /** Return the Latin letter registered for a physical key because the active layout does not produce it, or `undefined`. */ getLatinLetterFallback(key: Key): string | undefined; /** * Called when a KeyboardEvent is processed by the KeybindingRegistry. * The KeyValidator may trigger a keyboard layout change. */ validateKeyCode(keyCode: KeyCode, input: NormalizedKeyboardInput): void; protected transformNativeLayout(nativeLayout: NativeKeyboardLayout): KeyboardLayout; protected shouldIncludeKey(code: string): boolean; protected layoutModifierCost(layoutModifiers: LayoutModifiers): number; /** * Register VS Code-compatible US-position fallbacks for Latin letters that the layout does not produce * on its base or Shift layer. This is called once whenever the active keyboard layout is transformed. */ protected addMissingLatinLetterCandidates(candidatesByCharacter: Map<string, KeyboardLayoutCandidate[]>): Map<string, string>; private addKeyMappings; private addKeyMapping; } //# sourceMappingURL=keyboard-layout-service.d.ts.map