123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- /*---------------------------------------------------------------------------------------------
- * 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 createKeybinding(keybinding, OS) {
- if (keybinding === 0) {
- return null;
- }
- const firstPart = (keybinding & 0x0000FFFF) >>> 0;
- const chordPart = (keybinding & 0xFFFF0000) >>> 16;
- if (chordPart !== 0) {
- return new ChordKeybinding([
- createSimpleKeybinding(firstPart, OS),
- createSimpleKeybinding(chordPart, OS)
- ]);
- }
- return new ChordKeybinding([createSimpleKeybinding(firstPart, OS)]);
- }
- export function createSimpleKeybinding(keybinding, OS) {
- const ctrlCmd = (keybinding & 2048 /* CtrlCmd */ ? true : false);
- const winCtrl = (keybinding & 256 /* WinCtrl */ ? true : false);
- const ctrlKey = (OS === 2 /* Macintosh */ ? winCtrl : ctrlCmd);
- const shiftKey = (keybinding & 1024 /* Shift */ ? true : false);
- const altKey = (keybinding & 512 /* Alt */ ? true : false);
- const metaKey = (OS === 2 /* Macintosh */ ? ctrlCmd : winCtrl);
- const keyCode = (keybinding & 255 /* KeyCode */);
- return new SimpleKeybinding(ctrlKey, shiftKey, altKey, metaKey, keyCode);
- }
- export class SimpleKeybinding {
- constructor(ctrlKey, shiftKey, altKey, metaKey, keyCode) {
- this.ctrlKey = ctrlKey;
- this.shiftKey = shiftKey;
- this.altKey = altKey;
- this.metaKey = metaKey;
- this.keyCode = keyCode;
- }
- equals(other) {
- return (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 /* Unknown */
- || this.keyCode === 5 /* Ctrl */
- || this.keyCode === 57 /* Meta */
- || this.keyCode === 6 /* Alt */
- || this.keyCode === 4 /* Shift */);
- }
- toChord() {
- return new ChordKeybinding([this]);
- }
- /**
- * 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 /* Ctrl */)
- || (this.shiftKey && this.keyCode === 4 /* Shift */)
- || (this.altKey && this.keyCode === 6 /* Alt */)
- || (this.metaKey && this.keyCode === 57 /* Meta */));
- }
- }
- export class ChordKeybinding {
- constructor(parts) {
- if (parts.length === 0) {
- throw illegalArgument(`parts`);
- }
- this.parts = parts;
- }
- }
- export class ScanCodeBinding {
- 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 /* ControlLeft */ || this.scanCode === 161 /* ControlRight */))
- || (this.shiftKey && (this.scanCode === 158 /* ShiftLeft */ || this.scanCode === 162 /* ShiftRight */))
- || (this.altKey && (this.scanCode === 159 /* AltLeft */ || this.scanCode === 163 /* AltRight */))
- || (this.metaKey && (this.scanCode === 160 /* MetaLeft */ || this.scanCode === 164 /* MetaRight */)));
- }
- }
- export class ResolvedKeybindingPart {
- constructor(ctrlKey, shiftKey, altKey, metaKey, kbLabel, kbAriaLabel) {
- this.ctrlKey = ctrlKey;
- this.shiftKey = shiftKey;
- this.altKey = altKey;
- this.metaKey = metaKey;
- this.keyLabel = kbLabel;
- this.keyAriaLabel = kbAriaLabel;
- }
- }
- /**
- * A resolved keybinding. Can be a simple keybinding or a chord keybinding.
- */
- export class ResolvedKeybinding {
- }
|