combineTextEditInfos.ts ×11

Frontier kind: Code frontier

unlabeled · c_3e11e2b86554

51 tests · 41936 LOC · 238 files · introduces 0 tests · 91 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges91 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5308 ranges41936 lines · 238 files · Browse complete extent
All tests (intent)
51 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.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

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

3 files ranked by introduced lines: 91 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/combineTextEditInfos.ts 83 introduced LOC · 11 ranges

Open complete file

12 return textEditInfoSecond;
13 }
14 > if (textEditInfoSecond.length === 0) { combineTextEditInfos.ts
15 return textEditInfoFirst;
16 }
18 > // s0: State before any edits
19 > const s0ToS1Map = new ArrayQueue(toLengthMapping(textEditInfoFirst));
20 > // s1: State after first edit, but before second edit
21 > const s1ToS2Map = toLengthMapping(textEditInfoSecond) as (LengthMapping | { lengthBefore: undefined; lengthAfter: undefined; modified: false })[];
22 > s1ToS2Map.push({ modified: false, lengthBefore: undefined, lengthAfter: undefined }); // Copy everything from old to new
23 > // s2: State after both edits
24 >
25 > let curItem: LengthMapping | undefined = s0ToS1Map.dequeue();
26 >
27 > /**
28 > * @param s1Length Use undefined for length "infinity"
29 > */
30 > function nextS0ToS1MapWithS1LengthOf(s1Length: Length | undefined): LengthMapping[] {
31 > if (s1Length === undefined) {
32 > const arr = s0ToS1Map.takeWhile(v => true) || [];
33 > if (curItem) {
34 arr.unshift(curItem);
35 }
36 > return arr; combineTextEditInfos.ts
37 > }
38 >
39 > const result: LengthMapping[] = [];
40 > while (curItem && !lengthIsZero(s1Length)) {
41 > const [item, remainingItem] = curItem.splitAt(s1Length);
42 > result.push(item);
43 > s1Length = lengthDiffNonNegative(item.lengthAfter, s1Length);
44 > curItem = remainingItem ?? s0ToS1Map.dequeue();
45 > }
46 > if (!lengthIsZero(s1Length)) {
47 result.push(new LengthMapping(false, s1Length, s1Length));
48 }
49 > return result; combineTextEditInfos.ts
50 > }
51 >
52 > const result: TextEditInfo[] = [];
53 >
54 > function pushEdit(startOffset: Length, endOffset: Length, newLength: Length): void {
55 > if (result.length > 0 && lengthEquals(result[result.length - 1].endOffset, startOffset)) {
56 const lastResult = result[result.length - 1];
57 result[result.length - 1] = new TextEditInfo(lastResult.startOffset, endOffset, lengthAdd(lastResult.newLength, newLength));
58 > } else { combineTextEditInfos.ts
59 > result.push({ startOffset, endOffset, newLength });
60 > }
61 > }
62 >
63 > let s0offset = lengthZero;
64 > for (const s1ToS2 of s1ToS2Map) {
65 > const s0ToS1Map = nextS0ToS1MapWithS1LengthOf(s1ToS2.lengthBefore);
66 > if (s1ToS2.modified) {
67 > const s0Length = sumLengths(s0ToS1Map, s => s.lengthBefore);
68 > const s0EndOffset = lengthAdd(s0offset, s0Length);
69 > pushEdit(s0offset, s0EndOffset, s1ToS2.lengthAfter);
70 > s0offset = s0EndOffset;
71 > } else {
72 > for (const s1 of s0ToS1Map) {
73 const s0startOffset = s0offset;
74 s0offset = lengthAdd(s0offset, s1.lengthBefore);
77 }
78 }
80 > }
81 >
82 > return result;
83 > }
84
85 class LengthMapping {
86 constructor(
88 > * If false, length before and length after equal.
89 > */
90 > public readonly modified: boolean,
91 > public readonly lengthBefore: Length,
92 > public readonly lengthAfter: Length,
93 > ) {
94 > }
95
96 splitAt(lengthAfter: Length): [LengthMapping, LengthMapping | undefined] {
97 > const remainingLengthAfter = lengthDiffNonNegative(lengthAfter, this.lengthAfter); combineTextEditInfos.ts
98 > if (lengthEquals(remainingLengthAfter, lengthZero)) {
99 return [this, undefined];
100 > } else if (this.modified) { combineTextEditInfos.ts
101 return [
102 new LengthMapping(this.modified, this.lengthBefore, lengthAfter),
116 }
117
118 > function toLengthMapping(textEditInfos: TextEditInfo[]): LengthMapping[] { combineTextEditInfos.ts
119 > const result: LengthMapping[] = [];
120 > let lastOffset = lengthZero;
121 > for (const textEditInfo of textEditInfos) {
122 > const spaceLength = lengthDiffNonNegative(lastOffset, textEditInfo.startOffset);
123 > if (!lengthIsZero(spaceLength)) {
124 > result.push(new LengthMapping(false, spaceLength, spaceLength));
125 > }
126 >
127 > const lengthBefore = lengthDiffNonNegative(textEditInfo.startOffset, textEditInfo.endOffset);
128 > result.push(new LengthMapping(true, lengthBefore, textEditInfo.newLength));
129 > lastOffset = textEditInfo.endOffset;
130 > }
131 > return result;
132 > }
src/vs/base/common/arrays.ts 4 introduced LOC · 1 range

Open complete file

799
800 dequeue(): T | undefined {
801 > const result = this.items[this.firstIdx]; arrays.ts
802 > this.firstIdx++;
803 > return result;
804 > }
805
806 removeLast(): T | undefined {
src/vs/editor/common/model/bracketPairsTextModelPart/bracketPairsTree/length.ts 4 introduced LOC · 2 ranges

Open complete file

86
87 export function sumLengths<T>(items: readonly T[], lengthFn: (item: T) => Length): Length {
88 > return items.reduce((a, b) => lengthAdd(a, lengthFn(b)), lengthZero); length.ts
89 > }
90
91 export function lengthEquals(length1: Length, length2: Length): boolean {
92 > return length1 === length2; length.ts
93 > }
94
95 /**