textChange.ts ×26

Frontier kind: Code frontier

unlabeled · c_ab92713fa75e

872 tests · 5610 LOC · 30 files · introduces 0 tests · 78 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
26 ranges78 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
837 ranges5610 lines · 30 files · Browse complete extent
All tests (intent)
872 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.

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

src/vs/editor/common/core/textChange.ts 78 introduced LOC · 26 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- textChange.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 * as buffer from '../../../base/common/buffer.js';
7 > import { decodeUTF16LE } from './stringBuilder.js';
8 >
9 function escapeNewLine(str: string): string {
10 return (
14 );
15 }
17 > export class TextChange {
18 >
19 > public get oldLength(): number {
20 > return this.oldText.length;
21 > }
22 >
23 > public get oldEnd(): number {
24 return this.oldPosition + this.oldText.length;
25 }
27 > public get newLength(): number {
28 return this.newText.length;
29 }
31 > public get newEnd(): number {
32 return this.newPosition + this.newText.length;
33 }
35 > constructor(
36 public readonly oldPosition: number,
37 public readonly oldText: string,
39 public readonly newText: string
40 ) { }
42 > public toString(): string {
43 if (this.oldText.length === 0) {
44 return `(insert@${this.oldPosition} "${escapeNewLine(this.newText)}")`;
49 return `(replace@${this.oldPosition} "${escapeNewLine(this.oldText)}" with "${escapeNewLine(this.newText)}")`;
50 }
52 > private static _writeStringSize(str: string): number {
53 return (
54 4 + 2 * str.length
55 );
56 }
58 > private static _writeString(b: Uint8Array, str: string, offset: number): number {
59 const len = str.length;
60 buffer.writeUInt32BE(b, len, offset); offset += 4;
64 return offset;
65 }
67 > private static _readString(b: Uint8Array, offset: number): string {
68 const len = buffer.readUInt32BE(b, offset); offset += 4;
69 return decodeUTF16LE(b, offset, len);
70 }
72 > public writeSize(): number {
73 return (
74 + 4 // oldPosition
78 );
79 }
81 > public write(b: Uint8Array, offset: number): number {
82 buffer.writeUInt32BE(b, this.oldPosition, offset); offset += 4;
83 buffer.writeUInt32BE(b, this.newPosition, offset); offset += 4;
86 return offset;
87 }
89 > public static read(b: Uint8Array, offset: number, dest: TextChange[]): number {
90 const oldPosition = buffer.readUInt32BE(b, offset); offset += 4;
91 const newPosition = buffer.readUInt32BE(b, offset); offset += 4;
95 return offset;
96 }
97 > } textChange.ts
98 >
99 > export function compressConsecutiveTextChanges(prevEdits: TextChange[] | null, currEdits: TextChange[]): TextChange[] {
100 if (prevEdits === null || prevEdits.length === 0) {
101 return currEdits;
104 return compressor.compress();
105 }
107 > class TextChangeCompressor {
108 >
109 > private _prevEdits: TextChange[];
110 > private _currEdits: TextChange[];
111 >
112 > private _result: TextChange[];
113 > private _resultLen: number;
114 >
115 > private _prevLen: number;
116 > private _prevDeltaOffset: number;
117 >
118 > private _currLen: number;
119 > private _currDeltaOffset: number;
120 >
121 > constructor(prevEdits: TextChange[], currEdits: TextChange[]) {
122 this._prevEdits = prevEdits;
123 this._currEdits = currEdits;
132 this._currDeltaOffset = 0;
133 }
135 > public compress(): TextChange[] {
136 let prevIndex = 0;
137 let currIndex = 0;
218 return cleaned;
219 }
221 > private _acceptCurr(currEdit: TextChange): void {
222 this._result[this._resultLen++] = TextChangeCompressor._rebaseCurr(this._prevDeltaOffset, currEdit);
223 this._currDeltaOffset += currEdit.newLength - currEdit.oldLength;
224 }
226 > private _getCurr(currIndex: number): TextChange | null {
227 return (currIndex < this._currLen ? this._currEdits[currIndex] : null);
228 }
230 > private _acceptPrev(prevEdit: TextChange): void {
231 this._result[this._resultLen++] = TextChangeCompressor._rebasePrev(this._currDeltaOffset, prevEdit);
232 this._prevDeltaOffset += prevEdit.newLength - prevEdit.oldLength;
233 }
235 > private _getPrev(prevIndex: number): TextChange | null {
236 return (prevIndex < this._prevLen ? this._prevEdits[prevIndex] : null);
237 }
239 > private static _rebaseCurr(prevDeltaOffset: number, currEdit: TextChange): TextChange {
240 return new TextChange(
241 currEdit.oldPosition - prevDeltaOffset,
245 );
246 }
248 > private static _rebasePrev(currDeltaOffset: number, prevEdit: TextChange): TextChange {
249 return new TextChange(
250 prevEdit.oldPosition,
254 );
255 }
257 > private static _splitPrev(edit: TextChange, offset: number): [TextChange, TextChange] {
258 const preText = edit.newText.substr(0, offset);
259 const postText = edit.newText.substr(offset);
274 ];
275 }
277 > private static _splitCurr(edit: TextChange, offset: number): [TextChange, TextChange] {
278 const preText = edit.oldText.substr(0, offset);
279 const postText = edit.oldText.substr(offset);
294 ];
295 }
297 > private static _merge(edits: TextChange[]): TextChange[] {
298 if (edits.length === 0) {
299 return edits;
324 return result;
325 }
327 > private static _removeNoOps(edits: TextChange[]): TextChange[] {
328 if (edits.length === 0) {
329 return edits;