selection.ts ×16

Frontier kind: Code frontier

unlabeled · c_074e79a68f2d

886 tests · 5793 LOC · 30 files · introduces 0 tests · 141 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
16 ranges141 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
818 ranges5793 lines · 30 files · Browse complete extent
All tests (intent)
886 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: 141 introduced LOC across 16 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/core/selection.ts 141 introduced LOC · 16 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- selection.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 { IPosition, Position } from './position.js';
7 > import { Range } from './range.js';
8 >
9 > /**
10 > * A selection in the editor.
11 > * The selection is a range that has an orientation.
12 > */
13 > export interface ISelection {
14 > /**
15 > * The line number on which the selection has started.
16 > */
17 > readonly selectionStartLineNumber: number;
18 > /**
19 > * The column on `selectionStartLineNumber` where the selection has started.
20 > */
21 > readonly selectionStartColumn: number;
22 > /**
23 > * The line number on which the selection has ended.
24 > */
25 > readonly positionLineNumber: number;
26 > /**
27 > * The column on `positionLineNumber` where the selection has ended.
28 > */
29 > readonly positionColumn: number;
30 > }
31 >
32 > /**
33 > * The direction of a selection.
34 > */
35 > export const enum SelectionDirection {
36 > /**
37 > * The selection starts above where it ends.
38 > */
39 > LTR,
40 > /**
41 > * The selection starts below where it ends.
42 > */
43 > RTL
44 > }
45 >
46 > /**
47 > * A selection in the editor.
48 > * The selection is a range that has an orientation.
49 > */
50 > export class Selection extends Range {
51 > /**
52 > * The line number on which the selection has started.
53 > */
54 > public readonly selectionStartLineNumber: number;
55 > /**
56 > * The column on `selectionStartLineNumber` where the selection has started.
57 > */
58 > public readonly selectionStartColumn: number;
59 > /**
60 > * The line number on which the selection has ended.
61 > */
62 > public readonly positionLineNumber: number;
63 > /**
64 > * The column on `positionLineNumber` where the selection has ended.
65 > */
66 > public readonly positionColumn: number;
67 >
68 > constructor(selectionStartLineNumber: number, selectionStartColumn: number, positionLineNumber: number, positionColumn: number) {
69 super(selectionStartLineNumber, selectionStartColumn, positionLineNumber, positionColumn);
70 this.selectionStartLineNumber = selectionStartLineNumber;
73 this.positionColumn = positionColumn;
74 }
76 > /**
77 > * Transform to a human-readable representation.
78 > */
79 > public override toString(): string {
80 return '[' + this.selectionStartLineNumber + ',' + this.selectionStartColumn + ' -> ' + this.positionLineNumber + ',' + this.positionColumn + ']';
81 }
83 > /**
84 > * Test if equals other selection.
85 > */
86 > public equalsSelection(other: ISelection): boolean {
87 return (
88 Selection.selectionsEqual(this, other)
89 );
90 }
92 > /**
93 > * Test if the two selections are equal.
94 > */
95 > public static selectionsEqual(a: ISelection, b: ISelection): boolean {
96 return (
97 a.selectionStartLineNumber === b.selectionStartLineNumber &&
101 );
102 }
103 > selection.ts
104 > /**
105 > * Get directions (LTR or RTL).
106 > */
107 > public getDirection(): SelectionDirection {
108 if (this.selectionStartLineNumber === this.startLineNumber && this.selectionStartColumn === this.startColumn) {
109 return SelectionDirection.LTR;
111 return SelectionDirection.RTL;
112 }
113 > selection.ts
114 > /**
115 > * Create a new selection with a different `positionLineNumber` and `positionColumn`.
116 > */
117 > public override setEndPosition(endLineNumber: number, endColumn: number): Selection {
118 if (this.getDirection() === SelectionDirection.LTR) {
119 return new Selection(this.startLineNumber, this.startColumn, endLineNumber, endColumn);
121 return new Selection(endLineNumber, endColumn, this.startLineNumber, this.startColumn);
122 }
123 > selection.ts
124 > /**
125 > * Get the position at `positionLineNumber` and `positionColumn`.
126 > */
127 > public getPosition(): Position {
128 return new Position(this.positionLineNumber, this.positionColumn);
129 }
130 > selection.ts
131 > /**
132 > * Get the position at the start of the selection.
133 > */
134 > public getSelectionStart(): Position {
135 return new Position(this.selectionStartLineNumber, this.selectionStartColumn);
136 }
137 > selection.ts
138 > /**
139 > * Create a new selection with a different `selectionStartLineNumber` and `selectionStartColumn`.
140 > */
141 > public override setStartPosition(startLineNumber: number, startColumn: number): Selection {
142 if (this.getDirection() === SelectionDirection.LTR) {
143 return new Selection(startLineNumber, startColumn, this.endLineNumber, this.endColumn);
145 return new Selection(this.endLineNumber, this.endColumn, startLineNumber, startColumn);
146 }
147 > selection.ts
148 > // ----
149 >
150 > /**
151 > * Create a `Selection` from one or two positions
152 > */
153 > public static override fromPositions(start: IPosition, end: IPosition = start): Selection {
154 return new Selection(start.lineNumber, start.column, end.lineNumber, end.column);
155 }
156 > selection.ts
157 > /**
158 > * Creates a `Selection` from a range, given a direction.
159 > */
160 > public static fromRange(range: Range, direction: SelectionDirection): Selection {
161 if (direction === SelectionDirection.LTR) {
162 return new Selection(range.startLineNumber, range.startColumn, range.endLineNumber, range.endColumn);
165 }
166 }
167 > selection.ts
168 > /**
169 > * Create a `Selection` from an `ISelection`.
170 > */
171 > public static liftSelection(sel: ISelection): Selection {
172 return new Selection(sel.selectionStartLineNumber, sel.selectionStartColumn, sel.positionLineNumber, sel.positionColumn);
173 }
174 > selection.ts
175 > /**
176 > * `a` equals `b`.
177 > */
178 > public static selectionsArrEqual(a: ISelection[], b: ISelection[]): boolean {
179 if (a && !b || !a && b) {
180 return false;
193 return true;
194 }
195 > selection.ts
196 > /**
197 > * Test if `obj` is an `ISelection`.
198 > */
199 > public static isISelection(obj: unknown): obj is ISelection {
200 return (
201 !!obj
206 );
207 }
208 > selection.ts
209 > /**
210 > * Create with a direction.
211 > */
212 > public static createWithDirection(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, direction: SelectionDirection): Selection {
213
214 if (direction === SelectionDirection.LTR) {
218 return new Selection(endLineNumber, endColumn, startLineNumber, startColumn);
219 }
220 > } selection.ts