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.
/*---------------------------------------------------------------------------------------------
mockKeybindingService.ts ×37
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event } from '../../../../base/common/event.js';
import { KeyCodeChord, Keybinding, ResolvedKeybinding } from '../../../../base/common/keybindings.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { OS } from '../../../../base/common/platform.js';
import { ContextKeyExpression, ContextKeyValue, IContextKey, IContextKeyChangeEvent, IContextKeyService, IContextKeyServiceTarget, IScopedContextKeyService } from '../../../contextkey/common/contextkey.js';
import { IKeybindingService, IKeyboardEvent } from '../../common/keybinding.js';
import { NoMatchingKb, ResolutionResult } from '../../common/keybindingResolver.js';
import { ResolvedKeybindingItem } from '../../common/resolvedKeybindingItem.js';
import { USLayoutResolvedKeybinding } from '../../common/usLayoutResolvedKeybinding.js';
class MockKeybindingContextKey<T extends ContextKeyValue = ContextKeyValue> implements IContextKey<T> {
private _defaultValue: T | undefined;
private _value: T | undefined;
constructor(defaultValue: T | undefined) {
this._value = this._defaultValue;
}
public set(value: T | undefined): void {
}
public reset(): void {
}
public get(): T | undefined {
}
export class MockContextKeyService implements IContextKeyService {
public _serviceBrand: undefined;
private _keys = new Map<string, IContextKey<any>>();
public dispose(): void {
}
public createKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T | undefined): IContextKey<T> {
mockKeybindingService.ts ×37
this._keys.set(key, ret);
return ret;
}
public contextMatchesRules(rules: ContextKeyExpression): boolean {
mockKeybindingService.ts ×37
return false;
}
}
public getContextKeyValue(key: string) {
if (value) {
}
return null;
}
public createScoped(domNode: HTMLElement): IScopedContextKeyService {
mockKeybindingService.ts ×37
return this;
}
return this;
}
updateParent(_parentContextKeyService: IContextKeyService): void {
mockKeybindingService.ts ×37
// no-op
}
export class MockScopableContextKeyService extends MockContextKeyService {
/**
* Don't implement this for all tests since we rarely depend on this behavior and it isn't implemented fully
*/
public override createScoped(domNote: HTMLElement): IScopedContextKeyService {
return new MockScopableContextKeyService();
}
export class MockKeybindingService implements IKeybindingService {
public readonly inChordMode: boolean = false;
public get onDidUpdateKeybindings(): Event<void> {
return Event.None;
}
public getDefaultKeybindingsContent(): string {
return '';
}
public getDefaultKeybindings(): ResolvedKeybindingItem[] {
return [];
}
public getKeybindings(): ResolvedKeybindingItem[] {
return [];
}
public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
return USLayoutResolvedKeybinding.resolveKeybinding(keybinding, OS);
}
public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
const chord = new KeyCodeChord(
keyboardEvent.ctrlKey,
keyboardEvent.shiftKey,
keyboardEvent.altKey,
keyboardEvent.metaKey,
keyboardEvent.keyCode
);
return this.resolveKeybinding(chord.toKeybinding())[0];
}
public resolveUserBinding(userBinding: string): ResolvedKeybinding[] {
return [];
}
public lookupKeybindings(commandId: string): ResolvedKeybinding[] {
return [];
}
public lookupKeybinding(commandId: string): ResolvedKeybinding | undefined {
return undefined;
}
public customKeybindingsCount(): number {
return 0;
}
public softDispatch(keybinding: IKeyboardEvent, target: IContextKeyServiceTarget): ResolutionResult {
return NoMatchingKb;
}
public dispatchByUserSettingsLabel(userSettingsLabel: string, target: IContextKeyServiceTarget): void {
}
public dispatchEvent(e: IKeyboardEvent, target: IContextKeyServiceTarget): boolean {
return false;
}
public enableKeybindingHoldMode(commandId: string): undefined {
return undefined;
}
public mightProducePrintableCharacter(e: IKeyboardEvent): boolean {
return false;
}
public toggleLogging(): boolean {
return false;
}
public _dumpDebugInfo(): string {
return '';
}
public _dumpDebugInfoJSON(): string {
return '';
}
public registerSchemaContribution() {
return Disposable.None;
}
public appendKeybinding(label: string, _commandId: string, _context?: IContextKeyService, _enforceContextCheck?: boolean): string {
return label;
}