Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/common/src/types/Position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 conciseOneBase(): string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public conciseOneBase(): string {
public conciseOneBased(): string {

return `${this.line + 1}:${this.character + 1}`;
}

public toString(): string {
return this.concise();
}
Expand Down
12 changes: 10 additions & 2 deletions packages/common/src/types/Range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 conciseOneBase(): string {
return `${this.start.conciseOneBase()}-${this.end.conciseOneBase()}`;
}

public toString(): string {
return this.concise();
return `${this.start.concise()}-${this.end.concise()}`;
}
}
10 changes: 9 additions & 1 deletion packages/common/src/types/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 conciseOneBase(): string {
return `${this.start.conciseOneBase()}->${this.end.conciseOneBase()}`;
}

public toString(): string {
return this.concise();
}
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/types/position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).conciseOneBase(), "2:3");
});
});
5 changes: 5 additions & 0 deletions packages/common/src/types/range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).conciseOneBase(), "2:3-4:5");
});
});
5 changes: 5 additions & 0 deletions packages/common/src/types/selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).conciseOneBase(), "2:3->4:5");
});
});
Loading