arrayEdit.ts ×13

Frontier kind: Joint frontier

unlabeled · c_b77c8248751b

2112 tests · 6475 LOC · 39 files · introduces 1 test · 46 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges46 lines · 1 files
Tests
1 test

Contains — complete concept membership

All code (extent)
1082 ranges6475 lines · 39 files · Browse complete extent
All tests (intent)
2112 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

1 test introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 46 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/core/edits/arrayEdit.ts 46 introduced LOC · 13 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- arrayEdit.ts
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 { OffsetRange } from '../ranges/offsetRange.js';
7 > import { BaseEdit, BaseReplacement } from './edit.js';
8 >
9 > /**
10 > * Represents a set of replacements to an array.
11 > * All these replacements are applied at once.
12 > */
13 > export class ArrayEdit<T> extends BaseEdit<ArrayReplacement<T>, ArrayEdit<T>> {
14 > public static readonly empty = new ArrayEdit<never>([]);
15 >
16 > public static create<T>(replacements: readonly ArrayReplacement<T>[]): ArrayEdit<T> {
17 return new ArrayEdit(replacements);
18 }
20 > public static single<T>(replacement: ArrayReplacement<T>): ArrayEdit<T> {
21 return new ArrayEdit([replacement]);
22 }
24 > public static replace<T>(range: OffsetRange, replacement: readonly T[]): ArrayEdit<T> {
25 return new ArrayEdit([new ArrayReplacement(range, replacement)]);
26 }
28 > public static insert<T>(offset: number, replacement: readonly T[]): ArrayEdit<T> {
29 return new ArrayEdit([new ArrayReplacement(OffsetRange.emptyAt(offset), replacement)]);
30 }
32 > public static delete<T>(range: OffsetRange): ArrayEdit<T> {
33 return new ArrayEdit([new ArrayReplacement(range, [])]);
34 }
36 > protected override _createNew(replacements: readonly ArrayReplacement<T>[]): ArrayEdit<T> {
37 return new ArrayEdit(replacements);
38 }
40 > public apply(data: readonly T[]): readonly T[] {
41 const resultData: T[] = [];
42 let pos = 0;
49 return resultData;
50 }
52 > /**
53 > * Creates an edit that reverts this edit.
54 > */
55 > public inverse(baseVal: readonly T[]): ArrayEdit<T> {
56 const edits: ArrayReplacement<T>[] = [];
57 let offset = 0;
65 return new ArrayEdit(edits);
66 }
67 > } arrayEdit.ts
68 >
69 > export class ArrayReplacement<T> extends BaseReplacement<ArrayReplacement<T>> {
70 > constructor(
71 range: OffsetRange,
72 public readonly newValue: readonly T[]
74 super(range);
75 }
77 > override equals(other: ArrayReplacement<T>): boolean {
78 return this.replaceRange.equals(other.replaceRange) && this.newValue.length === other.newValue.length && this.newValue.every((v, i) => v === other.newValue[i]);
79 }
81 > getNewLength(): number { return this.newValue.length; }
82 >
83 > tryJoinTouching(other: ArrayReplacement<T>): ArrayReplacement<T> | undefined {
84 return new ArrayReplacement(this.replaceRange.joinRightTouching(other.replaceRange), this.newValue.concat(other.newValue));
85 }
87 > slice(range: OffsetRange, rangeInReplacement: OffsetRange): ArrayReplacement<T> {
88 return new ArrayReplacement(range, rangeInReplacement.slice(this.newValue));
89 }
90 > } arrayEdit.ts