Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/doc-ts-large-fn/resolver.ts
13399 views
1
function handleRemovals(rules: ResolvedKeybindingItem[]): ResolvedKeybindingItem[] {
2
// Do a first pass and construct a hash-map for removals
3
const removals = new Map</* commandId */ string, ResolvedKeybindingItem[]>();
4
for (let i = 0, len = rules.length; i < len; i++) {
5
const rule = rules[i];
6
if (rule.command && rule.command.charAt(0) === '-') {
7
const command = rule.command.substring(1);
8
if (!removals.has(command)) {
9
removals.set(command, [rule]);
10
} else {
11
removals.get(command)!.push(rule);
12
}
13
}
14
}
15
16
if (removals.size === 0) {
17
// There are no removals
18
return rules;
19
}
20
21
// Do a second pass and keep only non-removed keybindings
22
const result: ResolvedKeybindingItem[] = [];
23
for (let i = 0, len = rules.length; i < len; i++) {
24
const rule = rules[i];
25
26
if (!rule.command || rule.command.length === 0) {
27
result.push(rule);
28
continue;
29
}
30
if (rule.command.charAt(0) === '-') {
31
continue;
32
}
33
const commandRemovals = removals.get(rule.command);
34
if (!commandRemovals || !rule.isDefault) {
35
result.push(rule);
36
continue;
37
}
38
let isRemoved = false;
39
for (const commandRemoval of commandRemovals) {
40
const when = commandRemoval.when;
41
if (this._isTargetedForRemoval(rule, commandRemoval.chords, when)) {
42
isRemoved = true;
43
break;
44
}
45
}
46
if (!isRemoved) {
47
result.push(rule);
48
continue;
49
}
50
}
51
return result;
52
}
53
54