diff --git a/README.md b/README.md index c654f288..86ac1f09 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Addons are JavaScript modules that extend the `Terminal` prototype with new meth To use an addon, just import the JavaScript module and pass it to `Terminal`'s `applyAddon` method: ```javascript -import { Terminal } from xterm; +import { Terminal } from 'xterm'; import * as fit from 'xterm/lib/addons/fit/fit'; diff --git a/src/Buffer.ts b/src/Buffer.ts index df4134ee..74750a8b 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -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 ''; diff --git a/src/BufferLine.test.ts b/src/BufferLine.test.ts index 93b2759f..fbf8b051 100644 --- a/src/BufferLine.test.ts +++ b/src/BufferLine.test.ts @@ -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(''); + }); }); }); diff --git a/src/BufferLine.ts b/src/BufferLine.ts index bcc3d1bb..3f93af62 100644 --- a/src/BufferLine.ts +++ b/src/BufferLine.ts @@ -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; } @@ -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; diff --git a/src/SelectionManager.ts b/src/SelectionManager.ts index 4bac0400..1aea1cb5 100644 --- a/src/SelectionManager.ts +++ b/src/SelectionManager.ts @@ -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