Skip to content

Commit

Permalink
Merge pull request #3363 from meganrogge/bufferRange
Browse files Browse the repository at this point in the history
+1 to rangeLength when on a wrapped line to match standard behavior
  • Loading branch information
Tyriar authored Jun 9, 2021
2 parents 19c9fef + fdae613 commit 6dd61f9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/common/buffer/BufferRange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ describe('BufferRange', () => {
assert.throws(() => getRangeLength(createRange(1, 3, 1, 1), 0));
});
it('should get range multiple lines', () => {
assert.equal(getRangeLength(createRange(1, 1, 4, 5), 5), 23);
assert.equal(getRangeLength(createRange(1, 1, 4, 5), 5), 24);
});
it('should get range for end line right after start line', () => {
assert.equal(getRangeLength(createRange(1, 1, 7, 2), 5), 11);
assert.equal(getRangeLength(createRange(1, 1, 7, 2), 5), 12);
});
});
});
Expand Down
7 changes: 2 additions & 5 deletions src/common/buffer/BufferRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@

import { IBufferRange } from 'xterm';

export function getRangeLength(range: IBufferRange, cols: number): number {
if (range.start.y === range.end.y) {
return range.end.x - range.start.x + 1;
}
export function getRangeLength(range: IBufferRange, bufferCols: number): number {
if (range.start.y > range.end.y) {
throw new Error(`Buffer range end (${range.end.x}, ${range.end.y}) cannot be before start (${range.start.x}, ${range.start.y})`);
}
return cols * (range.end.y - range.start.y - 1) + cols - range.start.x + range.end.x;
return bufferCols * (range.end.y - range.start.y) + (range.end.x - range.start.x + 1);
}

0 comments on commit 6dd61f9

Please sign in to comment.