1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.RawKeybinding = exports.Keybinding = void 0;
|
19 | const types_1 = require("./types");
|
20 | var Keybinding;
|
21 | (function (Keybinding) {
|
22 | |
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
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 |
|
43 |
|
44 |
|
45 |
|
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 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | function stringify(binding) {
|
70 | return JSON.stringify(apiObjectify(binding));
|
71 | }
|
72 | Keybinding.stringify = stringify;
|
73 |
|
74 | function is(arg) {
|
75 | return (0, types_1.isObject)(arg) && 'command' in arg && 'keybinding' in arg;
|
76 | }
|
77 | Keybinding.is = is;
|
78 | function replaceKeybinding(keybindings, oldKeybinding, newKeybinding) {
|
79 | const indexOld = keybindings.findIndex(keybinding => Keybinding.equals(keybinding, oldKeybinding, false, true));
|
80 | if (indexOld >= 0) {
|
81 | const indexNew = keybindings.findIndex(keybinding => Keybinding.equals(keybinding, newKeybinding, false, true));
|
82 | if (indexNew >= 0 && indexNew !== indexOld) {
|
83 |
|
84 | keybindings.splice(indexOld, 1);
|
85 | keybindings[indexNew] = newKeybinding;
|
86 | }
|
87 | else {
|
88 | keybindings[indexOld] = newKeybinding;
|
89 | }
|
90 | return true;
|
91 | }
|
92 | return false;
|
93 | }
|
94 | Keybinding.replaceKeybinding = replaceKeybinding;
|
95 | function addKeybinding(keybindings, newKeybinding) {
|
96 | const index = keybindings.findIndex(keybinding => Keybinding.equals(keybinding, newKeybinding, false, true));
|
97 | if (index >= 0) {
|
98 |
|
99 | keybindings[index] = newKeybinding;
|
100 | }
|
101 | else {
|
102 | keybindings.push(newKeybinding);
|
103 | }
|
104 | }
|
105 | Keybinding.addKeybinding = addKeybinding;
|
106 | })(Keybinding = exports.Keybinding || (exports.Keybinding = {}));
|
107 | var RawKeybinding;
|
108 | (function (RawKeybinding) {
|
109 | function is(candidate) {
|
110 | return (0, types_1.isObject)(candidate) && 'command' in candidate && 'key' in candidate;
|
111 | }
|
112 | RawKeybinding.is = is;
|
113 | })(RawKeybinding = exports.RawKeybinding || (exports.RawKeybinding = {}));
|
114 |
|
\ | No newline at end of file |