UNPKG

3.58 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.RawKeybinding = exports.Keybinding = void 0;
19const types_1 = require("./types");
20var Keybinding;
21(function (Keybinding) {
22 /**
23 * Compares two keybindings for equality.
24 * Can optionally ignore the keybinding and/or args property in the comparison.
25 * @param a The first Keybinding in the comparison
26 * @param b The second Keybinding in the comparison
27 * @param ignoreKeybinding Ignore the 'keybinding' property in the comparison
28 * @param ignoreArgs Ignore the 'args' property in the comparison
29 */
30 function equals(a, b, ignoreKeybinding = false, ignoreArgs = false) {
31 if (a.command === b.command &&
32 (a.context || '') === (b.context || '') &&
33 (a.when || '') === (b.when || '') &&
34 (ignoreKeybinding || a.keybinding === b.keybinding) &&
35 (ignoreArgs || (a.args || '') === (b.args || ''))) {
36 return true;
37 }
38 return false;
39 }
40 Keybinding.equals = equals;
41 /**
42 * Returns a new object only containing properties which
43 * are described on the `Keybinding` API.
44 *
45 * @param binding the binding to create an API object for.
46 */
47 function apiObjectify(binding) {
48 return {
49 command: binding.command,
50 keybinding: retrieveKeybinding(binding),
51 context: binding.context,
52 when: binding.when,
53 args: binding.args
54 };
55 }
56 Keybinding.apiObjectify = apiObjectify;
57 function retrieveKeybinding(binding) {
58 var _a, _b;
59 return (_b = (_a = binding.keybinding) !== null && _a !== void 0 ? _a : binding.key) !== null && _b !== void 0 ? _b : '';
60 }
61 Keybinding.retrieveKeybinding = retrieveKeybinding;
62 /**
63 * Returns with the string representation of the binding.
64 * Any additional properties which are not described on
65 * the `Keybinding` API will be ignored.
66 *
67 * @param binding the binding to stringify.
68 */
69 function stringify(binding) {
70 return JSON.stringify(apiObjectify(binding));
71 }
72 Keybinding.stringify = stringify;
73 /* Determine whether object is a KeyBinding */
74 function is(arg) {
75 return (0, types_1.isObject)(arg) && 'command' in arg && 'keybinding' in arg;
76 }
77 Keybinding.is = is;
78})(Keybinding = exports.Keybinding || (exports.Keybinding = {}));
79var RawKeybinding;
80(function (RawKeybinding) {
81 function is(candidate) {
82 return (0, types_1.isObject)(candidate) && 'command' in candidate && 'key' in candidate;
83 }
84 RawKeybinding.is = is;
85})(RawKeybinding = exports.RawKeybinding || (exports.RawKeybinding = {}));
86//# sourceMappingURL=keybinding.js.map
\No newline at end of file