Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/keybinding/common/keybinding.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
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
23
export interface IKeyboardEvent {
24
readonly _standardKeyboardEventBrand: true;
25
26
readonly ctrlKey: boolean;
27
readonly shiftKey: boolean;
28
readonly altKey: boolean;
29
readonly metaKey: boolean;
30
readonly altGraphKey: boolean;
31
readonly keyCode: KeyCode;
32
readonly code: string;
33
}
34
35
export interface KeybindingsSchemaContribution {
36
readonly onDidChange?: Event<void>;
37
38
getSchemaAdditions(): IJSONSchema[];
39
}
40
41
export const IKeybindingService = createDecorator<IKeybindingService>('keybindingService');
42
43
export interface IKeybindingService {
44
readonly _serviceBrand: undefined;
45
46
readonly inChordMode: boolean;
47
48
onDidUpdateKeybindings: Event<void>;
49
50
/**
51
* Returns none, one or many (depending on keyboard layout)!
52
*/
53
resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[];
54
55
resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding;
56
57
resolveUserBinding(userBinding: string): ResolvedKeybinding[];
58
59
/**
60
* Resolve and dispatch `keyboardEvent` and invoke the command.
61
*/
62
dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean;
63
64
/**
65
* Resolve and dispatch `keyboardEvent`, but do not invoke the command or change inner state.
66
*/
67
softDispatch(keyboardEvent: IKeyboardEvent, target: IContextKeyServiceTarget): ResolutionResult;
68
69
/**
70
* Enable hold mode for this command. This is only possible if the command is current being dispatched, meaning
71
* we are after its keydown and before is keyup event.
72
*
73
* @returns A promise that resolves when hold stops, returns undefined if hold mode could not be enabled.
74
*/
75
enableKeybindingHoldMode(commandId: string): Promise<void> | undefined;
76
77
dispatchByUserSettingsLabel(userSettingsLabel: string, target: IContextKeyServiceTarget): void;
78
79
/**
80
* Look up keybindings for a command.
81
* Use `lookupKeybinding` if you are interested in the preferred keybinding.
82
*/
83
lookupKeybindings(commandId: string): ResolvedKeybinding[];
84
85
/**
86
* Look up the preferred (last defined) keybinding for a command.
87
* @returns The preferred keybinding or null if the command is not bound.
88
*/
89
lookupKeybinding(commandId: string, context?: IContextKeyService, enforceContextCheck?: boolean): ResolvedKeybinding | undefined;
90
91
getDefaultKeybindingsContent(): string;
92
93
getDefaultKeybindings(): readonly ResolvedKeybindingItem[];
94
95
getKeybindings(): readonly ResolvedKeybindingItem[];
96
97
customKeybindingsCount(): number;
98
99
/**
100
* Will the given key event produce a character that's rendered on screen, e.g. in a
101
* text box. *Note* that the results of this function can be incorrect.
102
*/
103
mightProducePrintableCharacter(event: IKeyboardEvent): boolean;
104
105
registerSchemaContribution(contribution: KeybindingsSchemaContribution): IDisposable;
106
107
toggleLogging(): boolean;
108
109
_dumpDebugInfo(): string;
110
_dumpDebugInfoJSON(): string;
111
}
112
113