keybindingsMerge.ts ×17

Frontier kind: Code frontier

unlabeled · c_07d94f5db88f

12 tests · 21930 LOC · 133 files · introduces 0 tests · 74 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges74 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3030 ranges21930 lines · 133 files · Browse complete extent
All tests (intent)
12 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 74 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/userDataSync/common/keybindingsMerge.ts 74 introduced LOC · 17 ranges

Open complete file

55 return { mergeContent: localContent, hasChanges: true, hasConflicts: false };
56 }
58 > // Both local and remote has moved forward.
59 > const localByCommand = byCommand(local);
60 > const remoteByCommand = byCommand(remote);
61 const baseByCommand = base ? byCommand(base) : null;
62 const localToRemoteByCommand = compareByCommand(localByCommand, remoteByCommand, normalizedKeys);
74 mergeContent = removeKeybindings(mergeContent, command, formattingOptions);
75 }
77 > // Added commands in remote
78 > for (const command of commandsMergeResult.added.values()) {
79 if (commandsMergeResult.conflicts.has(command)) {
80 continue;
88 mergeContent = addKeybindings(mergeContent, keybindings, formattingOptions);
89 }
91 > // Updated commands in Remote
92 > for (const command of commandsMergeResult.updated.values()) {
93 if (commandsMergeResult.conflicts.has(command)) {
94 continue;
102 mergeContent = updateKeybindings(mergeContent, command, keybindings, formattingOptions);
103 }
105 > return { mergeContent, hasChanges: true, hasConflicts: commandsMergeResult.conflicts.size > 0 };
106 > }
107
108 > function computeMergeResult(localToRemote: ICompareResult, baseToLocal: ICompareResult, baseToRemote: ICompareResult): { added: Set<string>; removed: Set<string>; updated: Set<string>; conflicts: Set<string> } { keybindingsMerge.ts
109 > const added: Set<string> = new Set<string>();
110 > const removed: Set<string> = new Set<string>();
111 > const updated: Set<string> = new Set<string>();
112 > const conflicts: Set<string> = new Set<string>();
113 >
114 > // Removed keys in Local
115 > for (const key of baseToLocal.removed.values()) {
116 // Got updated in remote
117 if (baseToRemote.updated.has(key)) {
119 }
120 }
122 > // Removed keys in Remote
123 > for (const key of baseToRemote.removed.values()) {
124 if (conflicts.has(key)) {
125 continue;
133 }
134 }
136 > // Added keys in Local
137 > for (const key of baseToLocal.added.values()) {
138 if (conflicts.has(key)) {
139 continue;
147 }
148 }
150 > // Added keys in remote
151 > for (const key of baseToRemote.added.values()) {
152 if (conflicts.has(key)) {
153 continue;
163 }
164 }
166 > // Updated keys in Local
167 > for (const key of baseToLocal.updated.values()) {
168 if (conflicts.has(key)) {
169 continue;
177 }
178 }
180 > // Updated keys in Remote
181 > for (const key of baseToRemote.updated.values()) {
182 if (conflicts.has(key)) {
183 continue;
194 }
195 }
196 > return { added, removed, updated, conflicts }; keybindingsMerge.ts
197 > }
198
199 function computeMergeResultByKeybinding(local: IUserFriendlyKeybinding[], remote: IUserFriendlyKeybinding[], base: IUserFriendlyKeybinding[] | null, normalizedKeys: IStringDictionary<string>): IMergeResult {
218 return { hasLocalForwarded: true, hasRemoteForwarded: false, added: empty, removed: empty, updated: empty, conflicts: empty };
219 }
221 > const { added, removed, updated, conflicts } = computeMergeResult(localToRemoteByKeybinding, baseToLocalByKeybinding, baseToRemoteByKeybinding);
222 > return { hasLocalForwarded: true, hasRemoteForwarded: true, added, removed, updated, conflicts };
223 > }
224
225 function byKeybinding(keybindings: IUserFriendlyKeybinding[], keys: IStringDictionary<string>) {
238 }
239
240 > function byCommand(keybindings: IUserFriendlyKeybinding[]): Map<string, IUserFriendlyKeybinding[]> { keybindingsMerge.ts
241 > const map: Map<string, IUserFriendlyKeybinding[]> = new Map<string, IUserFriendlyKeybinding[]>();
242 > for (const keybinding of keybindings) {
243 > const command = keybinding.command[0] === '-' ? keybinding.command.substring(1) : keybinding.command;
244 > let value = map.get(command);
245 > if (!value) {
246 > value = [];
247 > map.set(command, value);
248 > }
249 > value.push(keybinding);
250 > }
251 > return map;
252 > }
253
254
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 }