1
>
/*---------------------------------------------------------------------------------------------
keybinding.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { Event } from '../../../base/common/event.js';
7
>
import { IJSONSchema } from '../../../base/common/jsonSchema.js';
8
>
import { KeyCode } from '../../../base/common/keyCodes.js';
9
>
import { ResolvedKeybinding, Keybinding } from '../../../base/common/keybindings.js';
10
>
import { IDisposable } from '../../../base/common/lifecycle.js';
11
>
import { IContextKeyService, IContextKeyServiceTarget } from '../../contextkey/common/contextkey.js';
12
>
import { createDecorator } from '../../instantiation/common/instantiation.js';
13
>
import { ResolutionResult } from './keybindingResolver.js';
14
>
import { ResolvedKeybindingItem } from './resolvedKeybindingItem.js';
15
>
16
>
export interface IUserFriendlyKeybinding {
17
>
key: string;
18
>
command: string;
19
>
args?: any;
20
>
when?: string;
21
>
/**
22
>
* When `true`, the keybinding is registered as a system-wide (OS global) shortcut that fires
23
>
* even when VS Code does not have focus. Desktop only; ignored on web/server. Only honored for
24
>
* user `keybindings.json` entries (not extension-contributed keybindings).
25
>
*/
26
>
systemWide?: boolean;
27
>
}
28
>
29
>
export interface IKeyboardEvent {
30
>
readonly _standardKeyboardEventBrand: true;
31
>
32
>
readonly ctrlKey: boolean;
33
>
readonly shiftKey: boolean;
34
>
readonly altKey: boolean;
35
>
readonly metaKey: boolean;
36
>
readonly altGraphKey: boolean;
37
>
readonly keyCode: KeyCode;
38
>
readonly code: string;
39
>
}
40
>
41
>
export interface KeybindingsSchemaContribution {
42
>
readonly onDidChange?: Event<void>;
43
>
44
>
getSchemaAdditions(): IJSONSchema[];
45
>
}
46
>
47
>
export const IKeybindingService = createDecorator<IKeybindingService>('keybindingService');
48
>
49
>
export interface IKeybindingService {
50
>
readonly _serviceBrand: undefined;
51
>
52
>
readonly inChordMode: boolean;
53
>
54
>
readonly onDidUpdateKeybindings: Event<void>;
55
>
56
>
/**
57
>
* Returns none, one or many (depending on keyboard layout)!
58
>
*/
59
>
resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[];
60
>
61
>
resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding;
62
>
63
>
resolveUserBinding(userBinding: string): ResolvedKeybinding[];
64
>
65
>
/**
66
>
* Resolve and dispatch `keyboardEvent` and invoke the command.
67
>
*/
68
>
dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean;
69
>
70
>
/**
71
>
* Resolve and dispatch `keyboardEvent`, but do not invoke the command or change inner state.
72
>
*/
73
>
softDispatch(keyboardEvent: IKeyboardEvent, target: IContextKeyServiceTarget): ResolutionResult;
74
>
75
>
/**
76
>
* Enable hold mode for this command. This is only possible if the command is current being dispatched, meaning
77
>
* we are after its keydown and before is keyup event.
78
>
*
79
>
* @returns A promise that resolves when hold stops, returns undefined if hold mode could not be enabled.
80
>
*/
81
>
enableKeybindingHoldMode(commandId: string): Promise<void> | undefined;
82
>
83
>
dispatchByUserSettingsLabel(userSettingsLabel: string, target: IContextKeyServiceTarget): void;
84
>
85
>
/**
86
>
* Look up keybindings for a command.
87
>
* Use `lookupKeybinding` if you are interested in the preferred keybinding.
88
>
*/
89
>
lookupKeybindings(commandId: string): ResolvedKeybinding[];
90
>
91
>
/**
92
>
* Look up the preferred (last defined) keybinding for a command.
93
>
* @returns The preferred keybinding or null if the command is not bound.
94
>
*/
95
>
lookupKeybinding(commandId: string, context?: IContextKeyService, enforceContextCheck?: boolean): ResolvedKeybinding | undefined;
96
>
97
>
getDefaultKeybindingsContent(): string;
98
>
99
>
getDefaultKeybindings(): readonly ResolvedKeybindingItem[];
100
>
101
>
getKeybindings(): readonly ResolvedKeybindingItem[];
102
>
103
>
customKeybindingsCount(): number;
104
>
105
>
/**
106
>
* Will the given key event produce a character that's rendered on screen, e.g. in a
107
>
* text box. *Note* that the results of this function can be incorrect.
108
>
*/
109
>
mightProducePrintableCharacter(event: IKeyboardEvent): boolean;
110
>
111
>
registerSchemaContribution(contribution: KeybindingsSchemaContribution): IDisposable;
112
>
113
>
toggleLogging(): boolean;
114
>
115
>
/**
116
>
* Given a UI element label and a command ID, appends the keybinding label if any.
117
>
* If the command is defined and has a keybinding, returns `${label} (keybinding label)`, otherwise just `label`.
118
>
*/
119
>
appendKeybinding(label: string, commandId: string | undefined | null, context?: IContextKeyService, enforceContextCheck?: boolean): string;
120
>
121
>
_dumpDebugInfo(): string;
122
>
_dumpDebugInfoJSON(): string;
123
>
}