src/vs/platform/keybinding/test/common/mockKeybindingService.ts

178 LOC · 119 covered · 59 uncovered · 49 ranges · 1103 concepts · 10 introducers · 539 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- mockKeybindingService.ts ×37
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 { KeyCodeChord, Keybinding, ResolvedKeybinding } from '../../../../base/common/keybindings.js';
8 > import { Disposable } from '../../../../base/common/lifecycle.js';
9 > import { OS } from '../../../../base/common/platform.js';
10 > import { ContextKeyExpression, ContextKeyValue, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IScopedContextKeyService } from '../../../contextkey/common/contextkey.js';
11 > import { IKeybindingService, IKeyboardEvent } from '../../common/keybinding.js';
12 > import { NoMatchingKb, ResolutionResult } from '../../common/keybindingResolver.js';
13 > import { ResolvedKeybindingItem } from '../../common/resolvedKeybindingItem.js';
14 > import { USLayoutResolvedKeybinding } from '../../common/usLayoutResolvedKeybinding.js';
15 >
16 > class MockKeybindingContextKey<T extends ContextKeyValue = ContextKeyValue> implements IContextKey<T> {
17 > private _defaultValue: T | undefined;
18 > private _value: T | undefined;
19 >
20 > constructor(defaultValue: T | undefined) {
21 > this._defaultValue = defaultValue; mockKeybindingService.ts ×2
22 > this._value = this._defaultValue;
23 > }
25 > public set(value: T | undefined): void {
26 > this._value = value; mockKeybindingService.ts ×1
27 > }
29 > public reset(): void {
30 > this._value = this._defaultValue; voiceChatService.ts ×11
31 > }
33 > public get(): T | undefined {
34 > return this._value; mockKeybindingService.ts ×2
35 > }
37 >
38 > export class MockContextKeyService implements IContextKeyService {
40 > public _serviceBrand: undefined;
41 > private _keys = new Map<string, IContextKey<any>>();
43 > public dispose(): void {
45 > }
46 > public createKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T | undefined): IContextKey<T> { mockKeybindingService.ts ×37
47 > const ret = new MockKeybindingContextKey(defaultValue); mockKeybindingService.ts ×2
48 > this._keys.set(key, ret);
49 > return ret;
50 > }
51 > public contextMatchesRules(rules: ContextKeyExpression): boolean { mockKeybindingService.ts ×37
52 return false;
53 }
54 > public get onDidChangeContext(): Event<IContextKeyChangeEvent> { mockKeybindingService.ts ×37
55 > return Event.None; mockKeybindingService.ts ×1
56 > }
57 > public bufferChangeEvents(callback: () => void) { callback(); } mockKeybindingService.ts ×37
58 > public getContextKeyValue(key: string) {
59 > const value = this._keys.get(key); mockKeybindingService.ts ×2
60 > if (value) {
61 > return value.get(); mockKeybindingService.ts ×2
62 > }
64 > public getContext(domNode: HTMLElement): any { mockKeybindingService.ts ×37
65 return null;
66 }
67 > public createScoped(domNode: HTMLElement): IScopedContextKeyService { mockKeybindingService.ts ×37
68 return this;
69 }
70 > public createOverlay(): IContextKeyService { mockKeybindingService.ts ×37
71 return this;
72 }
73 > updateParent(_parentContextKeyService: IContextKeyService): void { mockKeybindingService.ts ×37
74 // no-op
75 }
77 >
78 > export class MockScopableContextKeyService extends MockContextKeyService {
79 > /**
80 > * Don't implement this for all tests since we rarely depend on this behavior and it isn't implemented fully
81 > */
82 > public override createScoped(domNote: HTMLElement): IScopedContextKeyService {
83 return new MockScopableContextKeyService();
84 }
86 >
87 > export class MockKeybindingService implements IKeybindingService {
88 > public _serviceBrand: undefined; menuService.ts ×32
89 >
90 > public readonly inChordMode: boolean = false;
92 > public get onDidUpdateKeybindings(): Event<void> {
93 return Event.None;
94 }
96 > public getDefaultKeybindingsContent(): string {
97 return '';
98 }
100 > public getDefaultKeybindings(): ResolvedKeybindingItem[] {
101 return [];
102 }
104 > public getKeybindings(): ResolvedKeybindingItem[] {
105 return [];
106 }
108 > public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
109 return USLayoutResolvedKeybinding.resolveKeybinding(keybinding, OS);
110 }
112 > public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
113 const chord = new KeyCodeChord(
114 keyboardEvent.ctrlKey,
115 keyboardEvent.shiftKey,
116 keyboardEvent.altKey,
117 keyboardEvent.metaKey,
118 keyboardEvent.keyCode
119 );
120 return this.resolveKeybinding(chord.toKeybinding())[0];
121 }
123 > public resolveUserBinding(userBinding: string): ResolvedKeybinding[] {
124 return [];
125 }
127 > public lookupKeybindings(commandId: string): ResolvedKeybinding[] {
128 return [];
129 }
131 > public lookupKeybinding(commandId: string): ResolvedKeybinding | undefined {
132 return undefined;
133 }
135 > public customKeybindingsCount(): number {
136 return 0;
137 }
139 > public softDispatch(keybinding: IKeyboardEvent, target: IContextKeyServiceTarget): ResolutionResult {
140 return NoMatchingKb;
141 }
143 > public dispatchByUserSettingsLabel(userSettingsLabel: string, target: IContextKeyServiceTarget): void {
144
145 }
147 > public dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean {
148 return false;
149 }
151 > public enableKeybindingHoldMode(commandId: string): undefined {
152 return undefined;
153 }
155 > public mightProducePrintableCharacter(e: IKeyboardEvent): boolean {
156 return false;
157 }
159 > public toggleLogging(): boolean {
160 return false;
161 }
163 > public _dumpDebugInfo(): string {
164 return '';
165 }
167 > public _dumpDebugInfoJSON(): string {
168 return '';
169 }
171 > public registerSchemaContribution() {
172 return Disposable.None;
173 }
175 > public appendKeybinding(label: string, _commandId: string, _context?: IContextKeyService, _enforceContextCheck?: boolean): string {
176 return label;
177 }