diff --git a/packages/common/src/types/Position.ts b/packages/common/src/types/Position.ts index 317c237ad6..c4b25bc076 100644 --- a/packages/common/src/types/Position.ts +++ b/packages/common/src/types/Position.ts @@ -141,13 +141,21 @@ export class Position { } /** - * Return a concise string representation of the position. + * Return a concise string representation of the position. 0-based. * @returns concise representation **/ public concise(): string { return `${this.line}:${this.character}`; } + /** + * Return a concise string representation of the position. 1-based. + * @returns concise representation + **/ + public conciseOneBased(): string { + return `${this.line + 1}:${this.character + 1}`; + } + public toString(): string { return this.concise(); } diff --git a/packages/common/src/types/Range.ts b/packages/common/src/types/Range.ts index 1230bbc048..02aa3a6ea9 100644 --- a/packages/common/src/types/Range.ts +++ b/packages/common/src/types/Range.ts @@ -144,14 +144,22 @@ export class Range { } /** - * Return a concise string representation of the range + * Return a concise string representation of the range. 0-based. * @returns concise representation **/ public concise(): string { return `${this.start.concise()}-${this.end.concise()}`; } + /** + * Return a concise string representation of the range. 1-based. + * @returns concise representation + **/ + public conciseOneBased(): string { + return `${this.start.conciseOneBased()}-${this.end.conciseOneBased()}`; + } + public toString(): string { - return this.concise(); + return `${this.start.concise()}-${this.end.concise()}`; } } diff --git a/packages/common/src/types/Selection.ts b/packages/common/src/types/Selection.ts index a202c47251..5a5dc838db 100644 --- a/packages/common/src/types/Selection.ts +++ b/packages/common/src/types/Selection.ts @@ -74,13 +74,21 @@ export class Selection extends Range { } /** - * Return a concise string representation of the selection + * Return a concise string representation of the selection. 0-based. * @returns concise representation **/ public concise(): string { return `${this.anchor.concise()}->${this.active.concise()}`; } + /** + * Return a concise string representation of the selection. 1-based. + * @returns concise representation + **/ + public conciseOneBased(): string { + return `${this.start.conciseOneBased()}->${this.end.conciseOneBased()}`; + } + public toString(): string { return this.concise(); } diff --git a/packages/common/src/types/position.test.ts b/packages/common/src/types/position.test.ts index 07373396da..af095df91e 100644 --- a/packages/common/src/types/position.test.ts +++ b/packages/common/src/types/position.test.ts @@ -68,4 +68,9 @@ suite("Position", () => { new Position(1, 1).translate(undefined, 5).isEqual(new Position(1, 6)), ); }); + + test("concise", () => { + assert.equal(new Position(1, 2).concise(), "1:2"); + assert.equal(new Position(1, 2).conciseOneBased(), "2:3"); + }); }); diff --git a/packages/common/src/types/range.test.ts b/packages/common/src/types/range.test.ts index 3063e0a13d..ade8585b07 100644 --- a/packages/common/src/types/range.test.ts +++ b/packages/common/src/types/range.test.ts @@ -113,4 +113,9 @@ suite("Range", () => { assert.ok(new Range(1, 2, 3, 4).toSelection(true).isReversed); assert.ok(!new Range(1, 2, 3, 4).toSelection(false).isReversed); }); + + test("concise", () => { + assert.equal(new Range(1, 2, 3, 4).concise(), "1:2-3:4"); + assert.equal(new Range(1, 2, 3, 4).conciseOneBased(), "2:3-4:5"); + }); }); diff --git a/packages/common/src/types/selection.test.ts b/packages/common/src/types/selection.test.ts index b3d8f431be..4b967e1c82 100644 --- a/packages/common/src/types/selection.test.ts +++ b/packages/common/src/types/selection.test.ts @@ -49,4 +49,9 @@ suite("Selection", () => { assert.ok(new Selection(1, 2, 3, 4).toSelection(true).isReversed); assert.ok(!new Selection(1, 2, 3, 4).toSelection(false).isReversed); }); + + test("concise", () => { + assert.equal(new Selection(1, 2, 3, 4).concise(), "1:2->3:4"); + assert.equal(new Selection(1, 2, 3, 4).conciseOneBased(), "2:3->4:5"); + }); });