1
>
/*---------------------------------------------------------------------------------------------
mockKeybindingService.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 { 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;
22
this._value = this._defaultValue;
23
}
25
>
public set(value: T | undefined): void {
26
this._value = value;
27
}
29
>
public reset(): void {
30
this._value = this._defaultValue;
31
}
33
>
public get(): T | undefined {
34
return this._value;
35
}
37
>
38
>
export class MockContextKeyService implements IContextKeyService {
39
40
public _serviceBrand: undefined;
41
private _keys = new Map<string, IContextKey<any>>();
43
>
public dispose(): void {
44
//
45
}
46
>
public createKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T | undefined): IContextKey<T> {
mockKeybindingService.ts
47
const ret = new MockKeybindingContextKey(defaultValue);
48
this._keys.set(key, ret);
49
return ret;
50
}
52
return false;
53
}
55
return Event.None;
56
}
58
>
public getContextKeyValue(key: string) {
59
const value = this._keys.get(key);
60
if (value) {