Merge pull request #1843 from Tyriar/endcol_null
Fix translateToString endCol default arg
This commit is contained in:
+1
-1
@@ -275,7 +275,7 @@ export class Buffer implements IBuffer {
|
|||||||
* @param startCol The column to start at.
|
* @param startCol The column to start at.
|
||||||
* @param endCol The column to end 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);
|
const line = this.lines.get(lineIndex);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
@@ -325,5 +325,10 @@ describe('BufferLine', function(): void {
|
|||||||
chai.expect(line.translateToString(false)).equal(' ');
|
chai.expect(line.translateToString(false)).equal(' ');
|
||||||
chai.expect(line.translateToString(true)).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('');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-8
@@ -118,13 +118,12 @@ export class BufferLineJSArray implements IBufferLine {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = null): string {
|
public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = this.length): string {
|
||||||
let length = endCol || this.length;
|
|
||||||
if (trimRight) {
|
if (trimRight) {
|
||||||
length = Math.min(length, this.getTrimmedLength());
|
endCol = Math.min(endCol, this.getTrimmedLength());
|
||||||
}
|
}
|
||||||
let result = '';
|
let result = '';
|
||||||
while (startCol < length) {
|
while (startCol < endCol) {
|
||||||
result += this.get(startCol)[CHAR_DATA_CHAR_INDEX] || WHITESPACE_CELL_CHAR;
|
result += this.get(startCol)[CHAR_DATA_CHAR_INDEX] || WHITESPACE_CELL_CHAR;
|
||||||
startCol += this.get(startCol)[CHAR_DATA_WIDTH_INDEX] || 1;
|
startCol += this.get(startCol)[CHAR_DATA_WIDTH_INDEX] || 1;
|
||||||
}
|
}
|
||||||
@@ -305,13 +304,12 @@ export class BufferLine implements IBufferLine {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = null): string {
|
public translateToString(trimRight: boolean = false, startCol: number = 0, endCol: number = this.length): string {
|
||||||
let length = endCol || this.length;
|
|
||||||
if (trimRight) {
|
if (trimRight) {
|
||||||
length = Math.min(length, this.getTrimmedLength());
|
endCol = Math.min(endCol, this.getTrimmedLength());
|
||||||
}
|
}
|
||||||
let result = '';
|
let result = '';
|
||||||
while (startCol < length) {
|
while (startCol < endCol) {
|
||||||
const stringData = this._data[startCol * CELL_SIZE + Cell.STRING];
|
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;
|
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;
|
startCol += this._data[startCol * CELL_SIZE + Cell.WIDTH] || 1;
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ export class SelectionManager extends EventEmitter implements ISelectionManager
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Get first row
|
// 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));
|
result.push(this._buffer.translateBufferLineToString(start[1], true, start[0], startRowEndCol));
|
||||||
|
|
||||||
// Get middle rows
|
// Get middle rows
|
||||||
|
|||||||
Reference in New Issue
Block a user