Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/util/vs/base/common/sequence.ts
13405 views
1
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'
2
3
/*---------------------------------------------------------------------------------------------
4
* Copyright (c) Microsoft Corporation. All rights reserved.
5
* Licensed under the MIT License. See License.txt in the project root for license information.
6
*--------------------------------------------------------------------------------------------*/
7
8
import { Emitter, Event } from './event';
9
10
export interface ISplice<T> {
11
readonly start: number;
12
readonly deleteCount: number;
13
readonly toInsert: readonly T[];
14
}
15
16
export interface ISpliceable<T> {
17
splice(start: number, deleteCount: number, toInsert: readonly T[]): void;
18
}
19
20
export interface ISequence<T> {
21
readonly elements: T[];
22
readonly onDidSplice: Event<ISplice<T>>;
23
}
24
25
export class Sequence<T> implements ISequence<T>, ISpliceable<T> {
26
27
readonly elements: T[] = [];
28
29
private readonly _onDidSplice = new Emitter<ISplice<T>>();
30
readonly onDidSplice: Event<ISplice<T>> = this._onDidSplice.event;
31
32
splice(start: number, deleteCount: number, toInsert: readonly T[] = []): void {
33
this.elements.splice(start, deleteCount, ...toInsert);
34
this._onDidSplice.fire({ start, deleteCount, toInsert });
35
}
36
}
37
38