abstractText.ts ×16

Frontier kind: Code frontier

unlabeled · c_97edc5458438

3261 tests · 5826 LOC · 33 files · introduces 0 tests · 53 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges53 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
919 ranges5826 lines · 33 files · Browse complete extent
All tests (intent)
3261 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: 53 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/core/text/abstractText.ts 53 introduced LOC · 16 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- abstractText.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 { assert } from '../../../../base/common/assert.js';
7 > import { splitLines } from '../../../../base/common/strings.js';
8 > import { Position } from '../position.js';
9 > import { Range } from '../range.js';
10 > import { LineRange } from '../ranges/lineRange.js';
11 > import { OffsetRange } from '../ranges/offsetRange.js';
12 > import { TextLength } from '../text/textLength.js';
13 > import { PositionOffsetTransformer } from './positionToOffsetImpl.js';
14 >
15 > export abstract class AbstractText {
16 abstract getValueOfRange(range: Range): string;
17 abstract readonly length: TextLength;
38
39 private _transformer: PositionOffsetTransformer | undefined = undefined;
41 > getTransformer(): PositionOffsetTransformer {
42 if (!this._transformer) {
43 this._transformer = new PositionOffsetTransformer(this.getValue());
45 return this._transformer;
46 }
48 > getLineAt(lineNumber: number): string {
49 return this.getValueOfRange(new Range(lineNumber, 1, lineNumber, Number.MAX_SAFE_INTEGER));
50 }
52 > getLines(): string[] {
53 const value = this.getValue();
54 return splitLines(value);
55 }
57 > getLinesOfRange(range: LineRange): string[] {
58 return range.mapToLineArray(lineNumber => this.getLineAt(lineNumber));
59 }
61 > equals(other: AbstractText): boolean {
62 if (this === other) {
63 return true;
65 return this.getValue() === other.getValue();
66 }
68 >
69 > export class LineBasedText extends AbstractText {
70 > constructor(
71 private readonly _getLineContent: (lineNumber: number) => string,
72 private readonly _lineCount: number
76 super();
77 }
79 > override getValueOfRange(range: Range): string {
80 if (range.startLineNumber === range.endLineNumber) {
81 return this._getLineContent(range.startLineNumber).substring(range.startColumn - 1, range.endColumn - 1);
88 return result;
89 }
91 > override getLineLength(lineNumber: number): number {
92 return this._getLineContent(lineNumber).length;
93 }
95 > get length(): TextLength {
96 const lastLine = this._getLineContent(this._lineCount);
97 return new TextLength(this._lineCount - 1, lastLine.length);
98 }
100 >
101 > export class ArrayText extends LineBasedText {
102 > constructor(lines: string[]) {
103 super(
104 lineNumber => lines[lineNumber - 1],
106 );
107 }
108 > } abstractText.ts
109 >
110 > export class StringText extends AbstractText {
111 > private readonly _t;
112 >
113 > constructor(public readonly value: string) {
114 super();
115 this._t = new PositionOffsetTransformer(this.value);
116 }
118 > getValueOfRange(range: Range): string {
119 return this._t.getOffsetRange(range).substring(this.value);
120 }
122 > get length(): TextLength {
123 return this._t.textLength;
124 }
126 > // Override the getTransformer method to return the cached transformer
127 > override getTransformer() {
128 return this._t;
129 }
130 > } abstractText.ts