{"version":3,"sources":["browser/monaco-resolved-keybinding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAC,kBAAkB,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAM,OAAO,EAAe,WAAW,EAAY,MAAM,+BAA+B,CAAC;AAIhG,qBAAa,wBAAyB,SAAQ,MAAM,CAAC,WAAW,CAAC,kBAAkB;IAInE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;IAFvD,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,sBAAsB,EAAE,CAAC;gBAEvC,WAAW,EAAE,WAAW,EAAE,iBAAiB,EAAE,kBAAkB;IAiB9F,MAAM,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,UAAU,GAAG,MAAM;IAMtE,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,gBAAgB,GAAG,OAAO;IAyBxE,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,eAAe,GAAG,WAAW;IAI/E,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAS7B,QAAQ,IAAI,MAAM,GAAG,IAAI;IAIzB,YAAY,IAAI,MAAM,GAAG,IAAI;IAI7B,sBAAsB,IAAI,MAAM,GAAG,IAAI;IASvC,oBAAoB,IAAI,MAAM,GAAG,IAAI;IAIrC,SAAS,IAAI,OAAO;IAIpB,OAAO,IAAI,OAAO;IAIlB,gBAAgB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE;IAIrC,8BAA8B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE;IAInD,QAAQ,IAAI,MAAM,CAAC,WAAW,CAAC,sBAAsB,EAAE;IAI9D,OAAO,CAAC,YAAY;CAUvB","file":"../../src/browser/monaco-resolved-keybinding.d.ts","sourcesContent":["/********************************************************************************\r\n * Copyright (C) 2017 TypeFox and others.\r\n *\r\n * This program and the accompanying materials are made available under the\r\n * terms of the Eclipse Public License v. 2.0 which is available at\r\n * http://www.eclipse.org/legal/epl-2.0.\r\n *\r\n * This Source Code may also be made available under the following Secondary\r\n * Licenses when the conditions for such availability set forth in the Eclipse\r\n * Public License v. 2.0 are satisfied: GNU General Public License, version 2\r\n * with the GNU Classpath Exception which is available at\r\n * https://www.gnu.org/software/classpath/license.html.\r\n *\r\n * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0\r\n ********************************************************************************/\r\n\r\nimport {KeybindingRegistry} from '@tartjs/core/lib/browser/keybinding';\r\nimport {Key, KeyCode, KeyModifier, KeySequence, Keystroke} from '@tartjs/core/lib/browser/keys';\r\nimport {isOSX} from '@tartjs/core/lib/common/os';\r\nimport {KEY_CODE_MAP} from './monaco-keycode-map';\r\n\r\nexport class MonacoResolvedKeybinding extends monaco.keybindings.ResolvedKeybinding {\r\n\r\n    protected readonly parts: monaco.keybindings.ResolvedKeybindingPart[];\r\n\r\n    constructor(protected readonly keySequence: KeySequence, keybindingService: KeybindingRegistry) {\r\n        super();\r\n        this.parts = keySequence.map(keyCode => {\r\n            // eslint-disable-next-line no-null/no-null\r\n            const keyLabel = keyCode.key ? keybindingService.acceleratorForKey(keyCode.key) : null;\r\n            const keyAriaLabel = keyLabel;\r\n            return new monaco.keybindings.ResolvedKeybindingPart(\r\n                keyCode.ctrl,\r\n                keyCode.shift,\r\n                keyCode.alt,\r\n                keyCode.meta,\r\n                keyLabel,\r\n                keyAriaLabel\r\n            );\r\n        });\r\n    }\r\n\r\n    static toKeybinding(keybinding: monaco.keybindings.Keybinding): string {\r\n        return keybinding instanceof monaco.keybindings.SimpleKeybinding\r\n            ? this.keyCode(keybinding).toString()\r\n            : this.keySequence(keybinding as monaco.keybindings.ChordKeybinding).join(' ');\r\n    }\r\n\r\n    static keyCode(keybinding: monaco.keybindings.SimpleKeybinding): KeyCode {\r\n        const keyCode = keybinding.keyCode;\r\n        const sequence: Keystroke = {\r\n            first: Key.getKey(this.monaco2BrowserKeyCode(keyCode & 0xff)),\r\n            modifiers: []\r\n        };\r\n        if (keybinding.ctrlKey) {\r\n            if (isOSX) {\r\n                sequence.modifiers!.push(KeyModifier.MacCtrl);\r\n            } else {\r\n                sequence.modifiers!.push(KeyModifier.CtrlCmd);\r\n            }\r\n        }\r\n        if (keybinding.shiftKey) {\r\n            sequence.modifiers!.push(KeyModifier.Shift);\r\n        }\r\n        if (keybinding.altKey) {\r\n            sequence.modifiers!.push(KeyModifier.Alt);\r\n        }\r\n        if (keybinding.metaKey && sequence.modifiers!.indexOf(KeyModifier.CtrlCmd) === -1) {\r\n            sequence.modifiers!.push(KeyModifier.CtrlCmd);\r\n        }\r\n        return KeyCode.createKeyCode(sequence);\r\n    }\r\n\r\n    static keySequence(keybinding: monaco.keybindings.ChordKeybinding): KeySequence {\r\n        return keybinding.parts.map(part => this.keyCode(part));\r\n    }\r\n\r\n    private static monaco2BrowserKeyCode(keyCode: monaco.KeyCode): number {\r\n        for (let i = 0; i < KEY_CODE_MAP.length; i++) {\r\n            if (KEY_CODE_MAP[i] === keyCode) {\r\n                return i;\r\n            }\r\n        }\r\n        return -1;\r\n    }\r\n\r\n    public getLabel(): string | null {\r\n        return monaco.keybindings.UILabelProvider.toLabel(monaco.platform.OS, this.parts, p => p.keyLabel);\r\n    }\r\n\r\n    public getAriaLabel(): string | null {\r\n        return monaco.keybindings.UILabelProvider.toLabel(monaco.platform.OS, this.parts, p => p.keyAriaLabel);\r\n    }\r\n\r\n    public getElectronAccelerator(): string | null {\r\n        if (this.isChord()) {\r\n            // Electron cannot handle chords\r\n            // eslint-disable-next-line no-null/no-null\r\n            return null;\r\n        }\r\n        return monaco.keybindings.ElectronAcceleratorLabelProvider.toLabel(monaco.platform.OS, this.parts, p => p.keyLabel);\r\n    }\r\n\r\n    public getUserSettingsLabel(): string | null {\r\n        return monaco.keybindings.UserSettingsLabelProvider.toLabel(monaco.platform.OS, this.parts, p => p.keyLabel);\r\n    }\r\n\r\n    public isWYSIWYG(): boolean {\r\n        return true;\r\n    }\r\n\r\n    public isChord(): boolean {\r\n        return this.parts.length > 1;\r\n    }\r\n\r\n    public getDispatchParts(): (string | null)[] {\r\n        return this.keySequence.map(keyCode => monaco.keybindings.USLayoutResolvedKeybinding.getDispatchStr(this.toKeybinding(keyCode)));\r\n    }\r\n\r\n    public getSingleModifierDispatchParts(): (string | null)[] {\r\n        return []; /* NOOP */\r\n    }\r\n\r\n    public getParts(): monaco.keybindings.ResolvedKeybindingPart[] {\r\n        return this.parts;\r\n    }\r\n\r\n    private toKeybinding(keyCode: KeyCode): monaco.keybindings.SimpleKeybinding {\r\n        return new monaco.keybindings.SimpleKeybinding(\r\n            keyCode.ctrl,\r\n            keyCode.shift,\r\n            keyCode.alt,\r\n            keyCode.meta,\r\n            KEY_CODE_MAP[keyCode.key!.keyCode]\r\n        );\r\n    }\r\n\r\n}\r\n"]}