/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import { Emitter, Event } from './event.js'; export interface ISplice { readonly start: number; readonly deleteCount: number; readonly toInsert: readonly T[]; } export interface ISpliceable { splice(start: number, deleteCount: number, toInsert: readonly T[]): void; } export interface ISequence { readonly elements: T[]; readonly onDidSplice: Event>; } export class Sequence implements ISequence, ISpliceable { readonly elements: T[] = []; private readonly _onDidSplice = new Emitter>(); readonly onDidSplice: Event> = this._onDidSplice.event; splice(start: number, deleteCount: number, toInsert: readonly T[] = []): void { this.elements.splice(start, deleteCount, ...toInsert); this._onDidSplice.fire({ start, deleteCount, toInsert }); } }