Path: blob/main/src/vs/platform/keybinding/common/keybinding.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Event } from '../../../base/common/event.js';6import { IJSONSchema } from '../../../base/common/jsonSchema.js';7import { KeyCode } from '../../../base/common/keyCodes.js';8import { ResolvedKeybinding, Keybinding } from '../../../base/common/keybindings.js';9import { IDisposable } from '../../../base/common/lifecycle.js';10import { IContextKeyService, IContextKeyServiceTarget } from '../../contextkey/common/contextkey.js';11import { createDecorator } from '../../instantiation/common/instantiation.js';12import { ResolutionResult } from './keybindingResolver.js';13import { ResolvedKeybindingItem } from './resolvedKeybindingItem.js';1415export interface IUserFriendlyKeybinding {16key: string;17command: string;18args?: any;19when?: string;20}2122export interface IKeyboardEvent {23readonly _standardKeyboardEventBrand: true;2425readonly ctrlKey: boolean;26readonly shiftKey: boolean;27readonly altKey: boolean;28readonly metaKey: boolean;29readonly altGraphKey: boolean;30readonly keyCode: KeyCode;31readonly code: string;32}3334export interface KeybindingsSchemaContribution {35readonly onDidChange?: Event<void>;3637getSchemaAdditions(): IJSONSchema[];38}3940export const IKeybindingService = createDecorator<IKeybindingService>('keybindingService');4142export interface IKeybindingService {43readonly _serviceBrand: undefined;4445readonly inChordMode: boolean;4647onDidUpdateKeybindings: Event<void>;4849/**50* Returns none, one or many (depending on keyboard layout)!51*/52resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[];5354resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding;5556resolveUserBinding(userBinding: string): ResolvedKeybinding[];5758/**59* Resolve and dispatch `keyboardEvent` and invoke the command.60*/61dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean;6263/**64* Resolve and dispatch `keyboardEvent`, but do not invoke the command or change inner state.65*/66softDispatch(keyboardEvent: IKeyboardEvent, target: IContextKeyServiceTarget): ResolutionResult;6768/**69* Enable hold mode for this command. This is only possible if the command is current being dispatched, meaning70* we are after its keydown and before is keyup event.71*72* @returns A promise that resolves when hold stops, returns undefined if hold mode could not be enabled.73*/74enableKeybindingHoldMode(commandId: string): Promise<void> | undefined;7576dispatchByUserSettingsLabel(userSettingsLabel: string, target: IContextKeyServiceTarget): void;7778/**79* Look up keybindings for a command.80* Use `lookupKeybinding` if you are interested in the preferred keybinding.81*/82lookupKeybindings(commandId: string): ResolvedKeybinding[];8384/**85* Look up the preferred (last defined) keybinding for a command.86* @returns The preferred keybinding or null if the command is not bound.87*/88lookupKeybinding(commandId: string, context?: IContextKeyService, enforceContextCheck?: boolean): ResolvedKeybinding | undefined;8990getDefaultKeybindingsContent(): string;9192getDefaultKeybindings(): readonly ResolvedKeybindingItem[];9394getKeybindings(): readonly ResolvedKeybindingItem[];9596customKeybindingsCount(): number;9798/**99* Will the given key event produce a character that's rendered on screen, e.g. in a100* text box. *Note* that the results of this function can be incorrect.101*/102mightProducePrintableCharacter(event: IKeyboardEvent): boolean;103104registerSchemaContribution(contribution: KeybindingsSchemaContribution): IDisposable;105106toggleLogging(): boolean;107108_dumpDebugInfo(): string;109_dumpDebugInfoJSON(): string;110}111112113