Path: blob/main/src/vs/platform/keyboardLayout/common/keyboardMapper.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { ResolvedKeybinding, Keybinding } from '../../../base/common/keybindings.js';6import { IKeyboardEvent } from '../../keybinding/common/keybinding.js';78export interface IKeyboardMapper {9dumpDebugInfo(): string;10resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding;11resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[];12}1314export class CachedKeyboardMapper implements IKeyboardMapper {1516private _actual: IKeyboardMapper;17private _cache: Map<string, ResolvedKeybinding[]>;1819constructor(actual: IKeyboardMapper) {20this._actual = actual;21this._cache = new Map<string, ResolvedKeybinding[]>();22}2324public dumpDebugInfo(): string {25return this._actual.dumpDebugInfo();26}2728public resolveKeyboardEvent(keyboardEvent: IKeyboardEvent): ResolvedKeybinding {29return this._actual.resolveKeyboardEvent(keyboardEvent);30}3132public resolveKeybinding(keybinding: Keybinding): ResolvedKeybinding[] {33const hashCode = keybinding.getHashCode();34const resolved = this._cache.get(hashCode);35if (!resolved) {36const r = this._actual.resolveKeybinding(keybinding);37this._cache.set(hashCode, r);38return r;39}40return resolved;41}42}434445