Skip to content

Commit

Permalink
add test for correct tab handling, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jerch committed Jan 31, 2019
1 parent 21cb987 commit 7b7f85e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,13 @@ describe('Buffer', () => {
terminal.buffer.lines.get(bufferIndex[0]).get(bufferIndex[1])[CHAR_DATA_CHAR_INDEX]);
}
});

it('should handle \t in lines correctly', () => {
const input = '\thttps://google.de';
terminal.writeSync(input);
const s = terminal.buffer.iterator(true).next().content;
assert.equal(s, Array(terminal.getOption('tabStopWidth') + 1).join(' ') + 'https://google.de');
});
});
describe('BufferStringIterator', function(): void {
it('iterator does not overflow buffer limits', function(): void {
Expand Down
4 changes: 3 additions & 1 deletion src/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ export class Buffer implements IBuffer {
const length = (trimRight) ? line.getTrimmedLength() : line.length;
for (let i = 0; i < length; ++i) {
if (line.get(i)[CHAR_DATA_WIDTH_INDEX]) {
stringIndex -= line.get(i)[CHAR_DATA_CHAR_INDEX].length || 1; // WHITESPACE_CELL_CHAR.length
// empty cells report a string length of 0, but get replaced
// with a whitespace in translateToString, thus replace with 1
stringIndex -= line.get(i)[CHAR_DATA_CHAR_INDEX].length || 1;
}
if (stringIndex < 0) {
return [lineIndex, i];
Expand Down

0 comments on commit 7b7f85e

Please sign in to comment.