UNPKG

@theia/core

Version:

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

337 lines • 12.1 kB
export type KeySequence = KeyCode[]; export declare namespace KeySequence { function equals(a: KeySequence, b: KeySequence): boolean; enum CompareResult { NONE = 0, PARTIAL = 1, SHADOW = 2, FULL = 3 } function compare(a: KeySequence, b: KeySequence): CompareResult; function parse(keybinding: string): KeySequence; } /** * The key sequence for this binding. This key sequence should consist of one or more key strokes. Key strokes * consist of one or more keys held down at the same time. This should be zero or more modifier keys, and zero or one other key. * Since `M2+M3+<Key>` (Alt+Shift+<Key>) is reserved on MacOS X for writing special characters, such bindings are commonly * undefined for platform MacOS X and redefined as `M1+M3+<Key>`. The rule applies on the `M3+M2+<Key>` sequence. */ export interface Keystroke { readonly first?: Key; readonly modifiers?: KeyModifier[]; } /** * The keyboard-layout modifier layer used to produce a logical character, ordered by resolution cost. */ export type LayoutModifiers = 'none' | 'shift' | 'altGraph' | 'shiftAltGraph'; export declare function layoutModifiersIncludeShift(layoutModifiers: LayoutModifiers): boolean; export declare function layoutModifiersIncludeAltGraph(layoutModifiers: LayoutModifiers): boolean; export declare function isPrintableKey(key: Key): boolean; export declare function isPrintableCharacter(character: string | undefined): character is string; /** * Identifies how a key code was derived for runtime matching. * `authored` is the constructor default and represents an authored binding, even for manually constructed instances. * `commandModifiers` preserves the event's modifiers as command modifiers, while `layoutModifiers` attributes them to * the keyboard layout's character-producing layer. */ export type KeyCodeInterpretation = 'authored' | 'commandModifiers' | 'layoutModifiers'; export interface KeyCodeSchema { key?: Partial<Key>; ctrl?: boolean; shift?: boolean; alt?: boolean; meta?: boolean; character?: string; layoutModifiers?: LayoutModifiers; interpretation?: KeyCodeInterpretation; supportedByLayout?: boolean; authoredToken?: string; physical?: boolean; } /** * Plain keyboard input data used by keybinding dispatch and diagnostics. */ export interface NormalizedKeyboardInput { key?: string; code?: string; keyCode?: number; charCode?: number; ctrlKey?: boolean; shiftKey?: boolean; altKey?: boolean; metaKey?: boolean; altGraph?: boolean; repeat?: boolean; isComposing?: boolean; location?: number; timeStamp?: number; keyIdentifier?: string; getModifierState?(keyArg: string): boolean; } /** * Read AltGraph state, preferring explicitly transported state over native event state. */ export declare function readAltGraph(input: NormalizedKeyboardInput): boolean; /** * Copy native or transported keyboard input into a normalized, transport-independent representation. * The parameter and result share this type because a native `KeyboardEvent` structurally satisfies the permissive input * shape. The returned data always has AltGraph resolved even though the field is optional in the input type. * `getModifierState` is retained for local diagnostics only and must not be relied on after transport. */ export declare function normalizeKeyboardInput(input: NormalizedKeyboardInput): NormalizedKeyboardInput; /** * Serialize a logical character for the keybinding grammar. * `+` and `-` are excluded from legacy bare spelling because they delimit key-code tokens. Uppercase ASCII letters are * escaped so their case is not lost by case-insensitive legacy key lookup. */ export declare function characterToken(character: string): string; /** * Representation of a pressed key combined with key modifiers. */ export declare class KeyCode { readonly key: Key | undefined; readonly ctrl: boolean; readonly shift: boolean; readonly alt: boolean; readonly meta: boolean; readonly character: string | undefined; readonly layoutModifiers: LayoutModifiers; readonly interpretation: KeyCodeInterpretation; /** Whether the authored logical character is available on the active keyboard layout. */ readonly supportedByLayout: boolean; readonly authoredToken: string | undefined; /** Whether the authored token denotes a physical scan code rather than a logical character. */ readonly physical: boolean; constructor(schema: KeyCodeSchema); /** * Return true if this KeyCode only contains modifiers. */ isModifierOnly(): boolean; /** * Return true if the given KeyCode is equal to this one. */ equals(other: KeyCode): boolean; /** * Return a keybinding string that round-trips the authored spelling through {@link authoredToken}. */ toString(): string; /** * Return the runtime match identity used for keybinding dispatch. * The interpretation is diagnostic metadata and does not affect this identity. */ dispatchString(): string; /** * Derive an authored keybinding stroke from a key event for recorder persistence. * This cannot use {@link toString}: event-derived key codes have no {@link authoredToken}, so `toString` would persist * the physical US key name instead of the committed logical character. Non-printable keys, Space and numpad keys are * persisted by name; printable keys without a committed character are persisted as scan codes. */ toAuthoredKeybindingString(): string; /** * Create a KeyCode from one of several input types. */ static createKeyCode(input: KeyboardEvent | NormalizedKeyboardInput | Keystroke | KeyCodeSchema | string, eventDispatch?: 'code' | 'keyCode'): KeyCode; private static keybindings; static resetKeyBindings(): void; /** * Parses a string and returns a KeyCode object. * @param keybinding String representation of a keybinding */ static parse(keybinding: string): KeyCode; } export declare namespace KeyCode { /** * Determines a `true` of `false` value for the key code argument. */ type Predicate = (keyCode: KeyCode) => boolean; function isModifierString(key: string): boolean; /** * Different scopes have different execution environments. This means that they have different built-ins * (different global object, different constructors, etc.). This may result in unexpected results. For instance, * `[] instanceof window.frames[0].Array` will return `false`, because `Array.prototype !== window.frames[0].Array` * and arrays inherit from the former. * See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof * * Note: just add another check if the current `event.type` checking is insufficient. */ function isKeyboardEvent(event: object & { readonly type?: string; }): event is KeyboardEvent; /** * Return true if the given object carries normalized keyboard input fields. */ function isNormalizedKeyboardInput(input: object): input is NormalizedKeyboardInput; /** * Determine the pressed key of a keyboard event. This key should correspond to the physical key according * to a standard US keyboard layout. International keyboard layouts are handled by `KeyboardLayoutService`. * * `keyIdentifier` is used to access this deprecated field: * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyIdentifier */ function toKey(event: NormalizedKeyboardInput, dispatch?: 'code' | 'keyCode'): Key; /** * Determine the actual printable character that is generated from a pressed key. * If the key does not correspond to a printable character, `undefined` is returned. * The result may be altered by modifier keys. */ function toCharacter(event: NormalizedKeyboardInput): string | undefined; } export declare enum KeyModifier { /** * M1 is the COMMAND key on MacOS X, and the CTRL key on most other platforms. */ CtrlCmd = "M1", /** * M2 is the SHIFT key. */ Shift = "M2", /** * M3 is the Option key on MacOS X, and the ALT key on most other platforms. */ Alt = "M3", /** * M4 is the CTRL key on MacOS X, and is undefined on other platforms. */ MacCtrl = "M4" } export declare namespace KeyModifier { /** * The CTRL key, independently of the platform. * _Note:_ In general `KeyModifier.CtrlCmd` should be preferred over this constant. */ const CTRL: KeyModifier.MacCtrl | KeyModifier.CtrlCmd; /** * An alias for the SHIFT key (`KeyModifier.Shift`). */ const SHIFT: KeyModifier.Shift; /** * `true` if the argument represents a modifier. Otherwise, `false`. */ function isModifier(key: string | undefined): boolean; } export interface Key { readonly code: string; readonly keyCode: number; readonly easyString: string; } export declare namespace SpecialCases { const META = "meta"; const CTRLCMD = "ctrlcmd"; } export declare namespace Key { function isKey(arg: unknown): arg is Key; function getKey(arg: string | number): Key | undefined; function isModifier(arg: string | number): boolean; function equals(key: Key, keyCode: KeyCode): boolean; const BACKSPACE: Key; const TAB: Key; const ENTER: Key; const ESCAPE: Key; const SPACE: Key; const PAGE_UP: Key; const PAGE_DOWN: Key; const END: Key; const HOME: Key; const ARROW_LEFT: Key; const ARROW_UP: Key; const ARROW_RIGHT: Key; const ARROW_DOWN: Key; const INSERT: Key; const DELETE: Key; const SHIFT_LEFT: Key; const SHIFT_RIGHT: Key; const CONTROL_LEFT: Key; const CONTROL_RIGHT: Key; const ALT_LEFT: Key; const ALT_RIGHT: Key; const CAPS_LOCK: Key; const OS_LEFT: Key; const OS_RIGHT: Key; const DIGIT0: Key; const DIGIT1: Key; const DIGIT2: Key; const DIGIT3: Key; const DIGIT4: Key; const DIGIT5: Key; const DIGIT6: Key; const DIGIT7: Key; const DIGIT8: Key; const DIGIT9: Key; const KEY_A: Key; const KEY_B: Key; const KEY_C: Key; const KEY_D: Key; const KEY_E: Key; const KEY_F: Key; const KEY_G: Key; const KEY_H: Key; const KEY_I: Key; const KEY_J: Key; const KEY_K: Key; const KEY_L: Key; const KEY_M: Key; const KEY_N: Key; const KEY_O: Key; const KEY_P: Key; const KEY_Q: Key; const KEY_R: Key; const KEY_S: Key; const KEY_T: Key; const KEY_U: Key; const KEY_V: Key; const KEY_W: Key; const KEY_X: Key; const KEY_Y: Key; const KEY_Z: Key; const MULTIPLY: Key; const ADD: Key; const DECIMAL: Key; const SUBTRACT: Key; const DIVIDE: Key; const F1: Key; const F2: Key; const F3: Key; const F4: Key; const F5: Key; const F6: Key; const F7: Key; const F8: Key; const F9: Key; const F10: Key; const F11: Key; const F12: Key; const F13: Key; const F14: Key; const F15: Key; const F16: Key; const F17: Key; const F18: Key; const F19: Key; const F20: Key; const F21: Key; const F22: Key; const F23: Key; const F24: Key; const NUM_LOCK: Key; const SEMICOLON: Key; const EQUAL: Key; const COMMA: Key; const MINUS: Key; const PERIOD: Key; const SLASH: Key; const BACKQUOTE: Key; const INTL_RO: Key; const BRACKET_LEFT: Key; const BACKSLASH: Key; const BRACKET_RIGHT: Key; const QUOTE: Key; const INTL_BACKSLASH: Key; const INTL_YEN: Key; const MAX_KEY_CODE: number; } export type KeysOrKeyCodes = Key | KeyCode | (Key | KeyCode)[]; export declare namespace KeysOrKeyCodes { const toKeyCode: (keyOrKeyCode: Key | KeyCode) => KeyCode; const toKeyCodes: (keysOrKeyCodes: KeysOrKeyCodes) => KeyCode[]; } //# sourceMappingURL=keys.d.ts.map