Skip to content

Commit 3856978

Browse files
committed
sequence module
1 parent d3df83b commit 3856978

7 files changed

Lines changed: 42 additions & 31 deletions

File tree

src/vs/base/browser/ui/list/list.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,3 @@ export interface IListContextMenuEvent<T> {
3636
index: number;
3737
anchor: HTMLElement | { x: number; y: number; };
3838
}
39-
40-
export interface ISpliceable<T> {
41-
splice(start: number, deleteCount: number, elements: T[]): void;
42-
}

src/vs/base/browser/ui/list/listView.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import { domEvent } from 'vs/base/browser/event';
1111
import { ScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
1212
import { ScrollEvent, ScrollbarVisibility } from 'vs/base/common/scrollable';
1313
import { RangeMap, IRange, relativeComplement } from './rangeMap';
14-
import { IDelegate, IRenderer, ISpliceable } from './list';
14+
import { IDelegate, IRenderer } from './list';
1515
import { RowCache, IRow } from './rowCache';
1616
import { isWindows } from 'vs/base/common/platform';
1717
import * as browser from 'vs/base/browser/browser';
18+
import { ISpliceable } from 'vs/base/common/sequence';
1819

1920
function canUseTranslate3d(): boolean {
2021
if (browser.isFirefox) {

src/vs/base/browser/ui/list/listWidget.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import { KeyCode } from 'vs/base/common/keyCodes';
1616
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
1717
import Event, { Emitter, EventBufferer, chain, mapEvent, fromCallback, anyEvent } from 'vs/base/common/event';
1818
import { domEvent } from 'vs/base/browser/event';
19-
import { IDelegate, IRenderer, IListEvent, IListMouseEvent, IListContextMenuEvent, ISpliceable } from './list';
19+
import { IDelegate, IRenderer, IListEvent, IListMouseEvent, IListContextMenuEvent } from './list';
2020
import { ListView, IListViewOptions } from './listView';
2121
import { Color } from 'vs/base/common/color';
2222
import { mixin } from 'vs/base/common/objects';
23+
import { ISpliceable } from 'vs/base/common/sequence';
2324

2425
export interface IIdentityProvider<T> {
2526
(element: T): string;

src/vs/base/common/arrays.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66

77
import { TPromise } from 'vs/base/common/winjs.base';
8+
import { ISplice } from 'vs/base/common/sequence';
89

910
/**
1011
* Returns the last element of an array.
@@ -124,30 +125,24 @@ export function groupBy<T>(data: T[], compare: (a: T, b: T) => number): T[][] {
124125
return result;
125126
}
126127

127-
export interface Splice<T> {
128-
start: number;
129-
deleteCount: number;
130-
inserted: T[];
131-
}
132-
133128
/**
134129
* Diffs two *sorted* arrays and computes the splices which apply the diff.
135130
*/
136-
export function sortedDiff<T>(before: T[], after: T[], compare: (a: T, b: T) => number): Splice<T>[] {
137-
const result: Splice<T>[] = [];
131+
export function sortedDiff<T>(before: T[], after: T[], compare: (a: T, b: T) => number): ISplice<T>[] {
132+
const result: ISplice<T>[] = [];
138133

139-
function pushSplice(start: number, deleteCount: number, inserted: T[]): void {
140-
if (deleteCount === 0 && inserted.length === 0) {
134+
function pushSplice(start: number, deleteCount: number, toInsert: T[]): void {
135+
if (deleteCount === 0 && toInsert.length === 0) {
141136
return;
142137
}
143138

144139
const latest = result[result.length - 1];
145140

146141
if (latest && latest.start + latest.deleteCount === start) {
147142
latest.deleteCount += deleteCount;
148-
latest.inserted.push(...inserted);
143+
latest.toInsert.push(...toInsert);
149144
} else {
150-
result.push({ start, deleteCount, inserted });
145+
result.push({ start, deleteCount, toInsert });
151146
}
152147
}
153148

@@ -199,7 +194,7 @@ export function delta<T>(before: T[], after: T[], compare: (a: T, b: T) => numbe
199194

200195
for (const splice of splices) {
201196
removed.push(...before.slice(splice.start, splice.start + splice.deleteCount));
202-
added.push(...splice.inserted);
197+
added.push(...splice.toInsert);
203198
}
204199

205200
return { removed, added };

src/vs/base/common/sequence.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
export interface ISplice<T> {
9+
start: number;
10+
deleteCount: number;
11+
toInsert: T[];
12+
}
13+
14+
export interface ISpliceable<T> {
15+
splice(start: number, deleteCount: number, toInsert: T[]): void;
16+
}

src/vs/workbench/api/node/extHostSCM.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import { asWinJsPromise } from 'vs/base/common/async';
1313
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
1414
import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands';
1515
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext } from './extHost.protocol';
16-
import { sortedDiff, Splice } from 'vs/base/common/arrays';
16+
import { sortedDiff } from 'vs/base/common/arrays';
1717
import { comparePaths } from 'vs/base/common/comparers';
1818
import * as vscode from 'vscode';
19+
import { ISplice } from 'vs/base/common/sequence';
1920

2021
type ProviderHandle = number;
2122
type GroupHandle = number;
@@ -221,8 +222,8 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
221222
const snapshot = [...this._resourceStates].sort(compareResourceStates);
222223
const diffs = sortedDiff(this._resourceSnapshot, snapshot, compareResourceStates);
223224

224-
const splices = diffs.map<Splice<{ rawResource: SCMRawResource, handle: number }>>(diff => {
225-
const inserted = diff.inserted.map(r => {
225+
const splices = diffs.map<ISplice<{ rawResource: SCMRawResource, handle: number }>>(diff => {
226+
const toInsert = diff.toInsert.map(r => {
226227
const handle = this._resourceHandlePool++;
227228
this._resourceStatesMap.set(handle, r);
228229

@@ -257,16 +258,16 @@ class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceG
257258
return { rawResource, handle };
258259
});
259260

260-
return { start: diff.start, deleteCount: diff.deleteCount, inserted };
261+
return { start: diff.start, deleteCount: diff.deleteCount, toInsert };
261262
});
262263

263264
const rawResourceSplices = splices
264-
.map(({ start, deleteCount, inserted }) => [start, deleteCount, inserted.map(i => i.rawResource)] as SCMRawResourceSplice);
265+
.map(({ start, deleteCount, toInsert }) => [start, deleteCount, toInsert.map(i => i.rawResource)] as SCMRawResourceSplice);
265266

266267
const reverseSplices = splices.reverse();
267268

268-
for (const { start, deleteCount, inserted } of reverseSplices) {
269-
const handles = inserted.map(i => i.handle);
269+
for (const { start, deleteCount, toInsert } of reverseSplices) {
270+
const handles = toInsert.map(i => i.handle);
270271
const handlesToDelete = this._handlesSnapshot.splice(start, deleteCount, ...handles);
271272

272273
for (const handle of handlesToDelete) {

src/vs/workbench/parts/scm/electron-browser/dirtydiffDecorator.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ import { basename } from 'vs/base/common/paths';
4646
import { MenuId, IMenuService, IMenu, MenuItemAction } from 'vs/platform/actions/common/actions';
4747
import { fillInActions, MenuItemActionItem } from 'vs/platform/actions/browser/menuItemActionItem';
4848
import { IChange, IEditorModel, ScrollType, IEditorContribution, OverviewRulerLane, IModel } from 'vs/editor/common/editorCommon';
49-
import { sortedDiff, Splice, firstIndex } from 'vs/base/common/arrays';
49+
import { sortedDiff, firstIndex } from 'vs/base/common/arrays';
5050
import { IMarginData } from 'vs/editor/browser/controller/mouseTarget';
5151
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
52+
import { ISplice } from 'vs/base/common/sequence';
5253

5354
// TODO@Joao
5455
// Need to subclass MenuItemActionItem in order to respect
@@ -584,14 +585,14 @@ export class DirtyDiffController implements IEditorContribution {
584585
return true;
585586
}
586587

587-
private onDidModelChange(splices: Splice<IChange>[]): void {
588+
private onDidModelChange(splices: ISplice<IChange>[]): void {
588589
for (const splice of splices) {
589590
if (splice.start <= this.currentIndex) {
590591
if (this.currentIndex < splice.start + splice.deleteCount) {
591592
this.currentIndex = -1;
592593
this.next();
593594
} else {
594-
this.currentIndex = rot(this.currentIndex + splice.inserted.length - splice.deleteCount - 1, this.model.changes.length);
595+
this.currentIndex = rot(this.currentIndex + splice.toInsert.length - splice.deleteCount - 1, this.model.changes.length);
595596
this.next();
596597
}
597598
}
@@ -849,8 +850,8 @@ export class DirtyDiffModel {
849850
private repositoryDisposables = new Set<IDisposable[]>();
850851
private disposables: IDisposable[] = [];
851852

852-
private _onDidChange = new Emitter<Splice<IChange>[]>();
853-
readonly onDidChange: Event<Splice<IChange>[]> = this._onDidChange.event;
853+
private _onDidChange = new Emitter<ISplice<IChange>[]>();
854+
readonly onDidChange: Event<ISplice<IChange>[]> = this._onDidChange.event;
854855

855856
private _changes: IChange[] = [];
856857
get changes(): IChange[] {

0 commit comments

Comments
 (0)