Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translateToString endCol default arg #1843

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class Buffer implements IBuffer {
* @param startCol The column to start at.
* @param endCol The column to end at.
*/
public translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol: number = 0, endCol: number = null): string {
public translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol: number = 0, endCol?: number): string {
const line = this.lines.get(lineIndex);
if (!line) {
return '';
Expand Down
5 changes: 5 additions & 0 deletions src/BufferLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,10 @@ describe('BufferLine', function(): void {
chai.expect(line.translateToString(false)).equal(' ');
chai.expect(line.translateToString(true)).equal('');
});
it('should work with endCol=0', () => {
const line = new TestBufferLine(10, [DEFAULT_ATTR, NULL_CELL_CHAR, 0, NULL_CELL_CODE], false);
line.set(0, [1, 'a', 1, 'a'.charCodeAt(0)]);
chai.expect(line.translateToString(true, 0, 0)).equal('');
});
});
});
14 changes: 6 additions & 8 deletions src/BufferLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,12 @@ export class BufferLineJSArray implements IBufferLine {
return 0;
}

public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = null): string {
let length = endCol || this.length;
public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = this.length): string {
if (trimRight) {
length = Math.min(length, this.getTrimmedLength());
endCol = Math.min(endCol, this.getTrimmedLength());
}
let result = '';
while (startCol < length) {
while (startCol < endCol) {
result += this.get(startCol)[CHAR_DATA_CHAR_INDEX] || WHITESPACE_CELL_CHAR;
startCol += this.get(startCol)[CHAR_DATA_WIDTH_INDEX] || 1;
}
Expand Down Expand Up @@ -305,13 +304,12 @@ export class BufferLine implements IBufferLine {
return 0;
}

public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = null): string {
let length = endCol || this.length;
public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = this.length): string {
if (trimRight) {
length = Math.min(length, this.getTrimmedLength());
endCol = Math.min(endCol, this.getTrimmedLength());
}
let result = '';
while (startCol < length) {
while (startCol < endCol) {
const stringData = this._data[startCol * CELL_SIZE + Cell.STRING];
result += (stringData & IS_COMBINED_BIT_MASK) ? this._combined[startCol] : (stringData) ? String.fromCharCode(stringData) : WHITESPACE_CELL_CHAR;
startCol += this._data[startCol * CELL_SIZE + Cell.WIDTH] || 1;
Expand Down
2 changes: 1 addition & 1 deletion src/SelectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
}
} else {
// Get first row
const startRowEndCol = start[1] === end[1] ? end[0] : null;
const startRowEndCol = start[1] === end[1] ? end[0] : undefined;
result.push(this._buffer.translateBufferLineToString(start[1], true, start[0], startRowEndCol));

// Get middle rows
Expand Down