Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/keyboardLayout/common/keyboardMapper.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 { ResolvedKeybinding, Keybinding } from '../../../base/common/keybindings.js';
7
import { IKeyboardEvent } from '../../keybinding/common/keybinding.js';
8
9
export interface IKeyboardMapper {
10
dumpDebugInfo(): string;
11
resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding;
12
resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[];
13
}
14
15
export class CachedKeyboardMapper implements IKeyboardMapper {
16
17
private _actual: IKeyboardMapper;
18
private _cache: Map<string, ResolvedKeybinding[]>;
19
20
constructor(actual: IKeyboardMapper) {
21
this._actual = actual;
22
this._cache = new Map<string, ResolvedKeybinding[]>();
23
}
24
25
public dumpDebugInfo(): string {
26
return this._actual.dumpDebugInfo();
27
}
28
29
public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {
30
return this._actual.resolveKeyboardEvent(keyboardEvent);
31
}
32
33
public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {
34
const hashCode = keybinding.getHashCode();
35
const resolved = this._cache.get(hashCode);
36
if (!resolved) {
37
const r = this._actual.resolveKeybinding(keybinding);
38
this._cache.set(hashCode, r);
39
return r;
40
}
41
return resolved;
42
}
43
}
44
45