move duplicated code into central place

This commit is contained in:
Johannes Rieken
2020-11-30 14:50:31 +01:00
parent 2c5901053a
commit aa36c6211b
3 changed files with 37 additions and 71 deletions

View File

@@ -30,41 +30,8 @@ import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/commo
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { IPathService } from 'vs/workbench/services/path/common/pathService';
import { diffSets, diffMaps } from 'vs/base/common/collections';
namespace delta {
export function ofSets<T>(before: Set<T>, after: Set<T>): { removed: T[], added: T[] } {
const removed: T[] = [];
const added: T[] = [];
for (let element of before) {
if (!after.has(element)) {
removed.push(element);
}
}
for (let element of after) {
if (!before.has(element)) {
added.push(element);
}
}
return { removed, added };
}
export function ofMaps<K, V>(before: Map<K, V>, after: Map<K, V>): { removed: V[], added: V[] } {
const removed: V[] = [];
const added: V[] = [];
for (let [index, value] of before) {
if (!after.has(index)) {
removed.push(value);
}
}
for (let [index, value] of after) {
if (!before.has(index)) {
added.push(value);
}
}
return { removed, added };
}
}
class TextEditorSnapshot {
@@ -117,8 +84,8 @@ class DocumentAndEditorState {
undefined, after.activeEditor
);
}
const documentDelta = delta.ofSets(before.documents, after.documents);
const editorDelta = delta.ofMaps(before.textEditors, after.textEditors);
const documentDelta = diffSets(before.documents, after.documents);
const editorDelta = diffMaps(before.textEditors, after.textEditors);
const oldActiveEditor = before.activeEditor !== after.activeEditor ? before.activeEditor : undefined;
const newActiveEditor = before.activeEditor !== after.activeEditor ? after.activeEditor : undefined;