textLength.ts ×21

Frontier kind: Code frontier

unlabeled · c_5e2752b8e109

3279 tests · 5702 LOC · 31 files · introduces 0 tests · 60 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
21 ranges60 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
884 ranges5702 lines · 31 files · Browse complete extent
All tests (intent)
3279 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: 60 introduced LOC across 21 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/core/text/textLength.ts 60 introduced LOC · 21 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- textLength.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 > import { LineRange } from '../ranges/lineRange.js';
6 > import { Position } from '../position.js';
7 > import { Range } from '../range.js';
8 > import { OffsetRange } from '../ranges/offsetRange.js';
9 >
10 > /**
11 > * Represents a non-negative length of text in terms of line and column count.
12 > */
13 > export class TextLength {
14 > public static zero = new TextLength(0, 0);
15 >
16 > public static lengthDiffNonNegative(start: TextLength, end: TextLength): TextLength {
17 if (end.isLessThan(start)) {
18 return TextLength.zero;
24 }
25 }
27 > public static betweenPositions(position1: Position, position2: Position): TextLength {
28 if (position1.lineNumber === position2.lineNumber) {
29 return new TextLength(0, position2.column - position1.column);
32 }
33 }
35 > public static fromPosition(pos: Position): TextLength {
36 return new TextLength(pos.lineNumber - 1, pos.column - 1);
37 }
39 > public static ofRange(range: Range) {
40 return TextLength.betweenPositions(range.getStartPosition(), range.getEndPosition());
41 }
43 > public static ofText(text: string): TextLength {
44 let line = 0;
45 let column = 0;
54 return new TextLength(line, column);
55 }
57 > public static ofSubstr(str: string, range: OffsetRange): TextLength {
58 return TextLength.ofText(range.substring(str));
59 }
61 > public static sum<T>(fragments: readonly T[], getLength: (f: T) => TextLength): TextLength {
62 return fragments.reduce((acc, f) => acc.add(getLength(f)), TextLength.zero);
63 }
65 > constructor(
66 > public readonly lineCount: number,
67 > public readonly columnCount: number
68 > ) { }
69 >
70 > public isZero() {
71 return this.lineCount === 0 && this.columnCount === 0;
72 }
74 > public isLessThan(other: TextLength): boolean {
75 if (this.lineCount !== other.lineCount) {
76 return this.lineCount < other.lineCount;
78 return this.columnCount < other.columnCount;
79 }
81 > public isGreaterThan(other: TextLength): boolean {
82 if (this.lineCount !== other.lineCount) {
83 return this.lineCount > other.lineCount;
85 return this.columnCount > other.columnCount;
86 }
88 > public isGreaterThanOrEqualTo(other: TextLength): boolean {
89 if (this.lineCount !== other.lineCount) {
90 return this.lineCount > other.lineCount;
92 return this.columnCount >= other.columnCount;
93 }
95 > public equals(other: TextLength): boolean {
96 return this.lineCount === other.lineCount && this.columnCount === other.columnCount;
97 }
99 > public compare(other: TextLength): number {
100 if (this.lineCount !== other.lineCount) {
101 return this.lineCount - other.lineCount;
103 return this.columnCount - other.columnCount;
104 }
106 > public add(other: TextLength): TextLength {
107 if (other.lineCount === 0) {
108 return new TextLength(this.lineCount, this.columnCount + other.columnCount);
111 }
112 }
114 > public createRange(startPosition: Position): Range {
115 if (this.lineCount === 0) {
116 return new Range(startPosition.lineNumber, startPosition.column, startPosition.lineNumber, startPosition.column + this.columnCount);
119 }
120 }
122 > public toRange(): Range {
123 return new Range(1, 1, this.lineCount + 1, this.columnCount + 1);
124 }
126 > public toLineRange(): LineRange {
127 return LineRange.ofLength(1, this.lineCount + 1);
128 }
130 > public addToPosition(position: Position): Position {
131 if (this.lineCount === 0) {
132 return new Position(position.lineNumber, position.column + this.columnCount);
135 }
136 }
138 > public addToRange(range: Range): Range {
139 return Range.fromPositions(
140 this.addToPosition(range.getStartPosition()),
142 );
143 }
145 > toString() {
146 return `${this.lineCount},${this.columnCount}`;
147 }
148 > } textLength.ts