| 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 |
import { Emitter, Event } from 'vs/base/common/event'; |
| 7 |
|
| 8 |
export interface ISplice<T> { |
| 9 |
readonly start: number; |
| 10 |
readonly deleteCount: number; |
| 11 |
readonly toInsert: readonly T[]; |
| 12 |
} |
| 13 |
|
| 14 |
export interface ISpliceable<T> { |
| 15 |
splice(start: number, deleteCount: number, toInsert: readonly T[]): void; |
| 16 |
} |
| 17 |
|
| 18 |
export interface ISequence<T> { |
| 19 |
readonly elements: T[]; |
| 20 |
readonly onDidSplice: Event<ISplice<T>>; |
| 21 |
} |
| 22 |
|
| 23 |
export class Sequence<T> implements ISequence<T>, ISpliceable<T> { |
| 24 |
|
| 25 |
readonly elements: T[] = []; |
| 26 |
|
| 27 |
private readonly _onDidSplice = new Emitter<ISplice<T>>(); |
| 28 |
readonly onDidSplice: Event<ISplice<T>> = this._onDidSplice.event; |
| 29 |
|
| 30 |
splice(start: number, deleteCount: number, toInsert: readonly T[] = []): void { |
| 31 |
this.elements.splice(start, deleteCount, ...toInsert); |
| 32 |
this._onDidSplice.fire({ start, deleteCount, toInsert }); |
| 33 |
} |
| 34 |
} |