1
>
/*---------------------------------------------------------------------------------------------
position.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
>
/**
7
>
* A position in the editor. This interface is suitable for serialization.
8
>
*/
9
>
export interface IPosition {
10
>
/**
11
>
* line number (starts at 1)
12
>
*/
13
>
readonly lineNumber: number;
14
>
/**
15
>
* column (the first character in a line is between column 1 and column 2)
16
>
*/
17
>
readonly column: number;
18
>
}
19
>
20
>
/**
21
>
* A position in the editor.
22
>
*/
23
>
export class Position {
24
>
/**
25
>
* line number (starts at 1)
26
>
*/
27
>
public readonly lineNumber: number;
28
>
/**
29
>
* column (the first character in a line is between column 1 and column 2)
30
>
*/
31
>
public readonly column: number;
32
>
33
>
constructor(lineNumber: number, column: number) {
34
this.lineNumber = lineNumber;
35
this.column = column;
36
}
38
>
/**
39
>
* Create a new position from this position.
40
>
*
41
>
* @param newLineNumber new line number
42
>
* @param newColumn new column
43
>
*/
44
>
with(newLineNumber: number = this.lineNumber, newColumn: number = this.column): Position {
45
if (newLineNumber === this.lineNumber && newColumn === this.column) {
46
return this;