| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- import { illegalArgument } from './errors.js';
- export function decodeKeybinding(keybinding, OS) {
- if (typeof keybinding === 'number') {
- if (keybinding === 0) {
- return null;
- }
- const firstChord = (keybinding & 0x0000FFFF) >>> 0;
- const secondChord = (keybinding & 0xFFFF0000) >>> 16;
- if (secondChord !== 0) {
- return new Keybinding([
- createSimpleKeybinding(firstChord, OS),
- createSimpleKeybinding(secondChord, OS)
- ]);
- }
- return new Keybinding([createSimpleKeybinding(firstChord, OS)]);
- }
- else {
- const chords = [];
- for (let i = 0; i < keybinding.length; i++) {
- chords.push(createSimpleKeybinding(keybinding[i], OS));
- }
- return new Keybinding(chords);
- }
- }
- export function createSimpleKeybinding(keybinding, OS) {
- const ctrlCmd = (keybinding & 2048 /* BinaryKeybindingsMask.CtrlCmd */ ? true : false);
- const winCtrl = (keybinding & 256 /* BinaryKeybindingsMask.WinCtrl */ ? true : false);
- const ctrlKey = (OS === 2 /* OperatingSystem.Macintosh */ ? winCtrl : ctrlCmd);
- const shiftKey = (keybinding & 1024 /* BinaryKeybindingsMask.Shift */ ? true : false);
- const altKey = (keybinding & 512 /* BinaryKeybindingsMask.Alt */ ? true : false);
- const metaKey = (OS === 2 /* OperatingSystem.Macintosh */ ? ctrlCmd : winCtrl);
- const keyCode = (keybinding & 255 /* BinaryKeybindingsMask.KeyCode */);
- return new KeyCodeChord(ctrlKey, shiftKey, altKey, metaKey, keyCode);
- }
- /**
- * Represents a chord which uses the `keyCode` field of keyboard events.
- * A chord is a combination of keys pressed simultaneously.
- */
- export class KeyCodeChord {
- constructor(ctrlKey, shiftKey, altKey, metaKey, keyCode) {
- this.ctrlKey = ctrlKey;
- this.shiftKey = shiftKey;
- this.altKey = altKey;
- this.metaKey = metaKey;
- this.keyCode = keyCode;
- }
- equals(other) {
- return (other instanceof KeyCodeChord
- && this.ctrlKey === other.ctrlKey
- && this.shiftKey === other.shiftKey
- && this.altKey === other.altKey
- && this.metaKey === other.metaKey
- && this.keyCode === other.keyCode);
- }
- isModifierKey() {
- return (this.keyCode === 0 /* KeyCode.Unknown */
- || this.keyCode === 5 /* KeyCode.Ctrl */
- || this.keyCode === 57 /* KeyCode.Meta */
- || this.keyCode === 6 /* KeyCode.Alt */
- || this.keyCode === 4 /* KeyCode.Shift */);
- }
- /**
- * Does this keybinding refer to the key code of a modifier and it also has the modifier flag?
- */
- isDuplicateModifierCase() {
- return ((this.ctrlKey && this.keyCode === 5 /* KeyCode.Ctrl */)
- || (this.shiftKey && this.keyCode === 4 /* KeyCode.Shift */)
- || (this.altKey && this.keyCode === 6 /* KeyCode.Alt */)
- || (this.metaKey && this.keyCode === 57 /* KeyCode.Meta */));
- }
- }
- /**
- * Represents a chord which uses the `code` field of keyboard events.
- * A chord is a combination of keys pressed simultaneously.
- */
- export class ScanCodeChord {
- constructor(ctrlKey, shiftKey, altKey, metaKey, scanCode) {
- this.ctrlKey = ctrlKey;
- this.shiftKey = shiftKey;
- this.altKey = altKey;
- this.metaKey = metaKey;
- this.scanCode = scanCode;
- }
- /**
- * Does this keybinding refer to the key code of a modifier and it also has the modifier flag?
- */
- isDuplicateModifierCase() {
- return ((this.ctrlKey && (this.scanCode === 157 /* ScanCode.ControlLeft */ || this.scanCode === 161 /* ScanCode.ControlRight */))
- || (this.shiftKey && (this.scanCode === 158 /* ScanCode.ShiftLeft */ || this.scanCode === 162 /* ScanCode.ShiftRight */))
- || (this.altKey && (this.scanCode === 159 /* ScanCode.AltLeft */ || this.scanCode === 163 /* ScanCode.AltRight */))
- || (this.metaKey && (this.scanCode === 160 /* ScanCode.MetaLeft */ || this.scanCode === 164 /* ScanCode.MetaRight */)));
- }
- }
- /**
- * A keybinding is a sequence of chords.
- */
- export class Keybinding {
- constructor(chords) {
- if (chords.length === 0) {
- throw illegalArgument(`chords`);
- }
- this.chords = chords;
- }
- }
- export class ResolvedChord {
- constructor(ctrlKey, shiftKey, altKey, metaKey, keyLabel, keyAriaLabel) {
- this.ctrlKey = ctrlKey;
- this.shiftKey = shiftKey;
- this.altKey = altKey;
- this.metaKey = metaKey;
- this.keyLabel = keyLabel;
- this.keyAriaLabel = keyAriaLabel;
- }
- }
- /**
- * A resolved keybinding. Consists of one or multiple chords.
- */
- export class ResolvedKeybinding {
- }
|