274
}
275
276
>
function compareByCommand(from: Map<string, IUserFriendlyKeybinding[]>, to: Map<string, IUserFriendlyKeybinding[]>, normalizedKeys: IStringDictionary<string>): ICompareResult {
keybindingsMerge.ts
277
>
const fromKeys = [...from.keys()];
278
>
const toKeys = [...to.keys()];
279
>
const added = toKeys.filter(key => !fromKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
280
>
const removed = fromKeys.filter(key => !toKeys.includes(key)).reduce((r, key) => { r.add(key); return r; }, new Set<string>());
281
>
const updated: Set<string> = new Set<string>();
282
>
283
>
for (const key of fromKeys) {
284
>
if (removed.has(key)) {
285
continue;
286
}
287
>
const value1: IUserFriendlyKeybinding[] = from.get(key)!.map(keybinding => ({ ...keybinding, ...{ key: normalizedKeys[keybinding.key] } }));
keybindingsMerge.ts
288
>
const value2: IUserFriendlyKeybinding[] = to.get(key)!.map(keybinding => ({ ...keybinding, ...{ key: normalizedKeys[keybinding.key] } }));
289
>
if (!areSameKeybindingsWithSameCommand(value1, value2)) {
290
updated.add(key);
291
}
293
>
294
>
return { added, removed, updated };
295
>
}
296
297
>
function areSameKeybindingsWithSameCommand(value1: IUserFriendlyKeybinding[], value2: IUserFriendlyKeybinding[]): boolean {
keybindingsMerge.ts
298
>
// Compare entries adding keybindings
299
>
if (!equals(value1.filter(({ command }) => command[0] !== '-'), value2.filter(({ command }) => command[0] !== '-'), (a, b) => isSameKeybinding(a, b))) {
300
return false;
301
}