diff --git a/src/Buffer.test.ts b/src/Buffer.test.ts index 1bd1ea38..aff9a57a 100644 --- a/src/Buffer.test.ts +++ b/src/Buffer.test.ts @@ -489,5 +489,22 @@ describe('Buffer', () => { const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, stringIndex); assert(terminal.buffer.lines.get(bufferIndex[0]).get(bufferIndex[1])[CHAR_DATA_CHAR_INDEX], '😃'); }); + it('multiline fullwidth chars with offset 1 (currently tests for broken behavior)', function(): void { + const input = 'a12345678901234567890'; + // the 'a' at the beginning moves all fullwidth chars one to the right + // now the end of the line contains a dangling empty cell since + // the next fullwidth char has to wrap early + // the dangling last cell is wrongly added in the string + // --> fixable after resolving #1685 + terminal.write(input); + // TODO: reenable after fix + // const s = terminal.buffer.contents(true).toArray()[0]; + // assert.equal(input, s); + for (let i = 10; i < input.length; ++i) { + const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i + 1); // TODO: remove +1 after fix + const j = (i - 0) << 1; + assert.deepEqual([(j / terminal.cols) | 0, j % terminal.cols], bufferIndex); + } + }); }); }); diff --git a/src/Buffer.ts b/src/Buffer.ts index e7a35d24..b807f51e 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -202,6 +202,7 @@ export class Buffer implements IBuffer { * The method operates on the CharData width attribute, there are no * additional content or boundary checks. Therefore the string and the buffer * should not be altered in between. + * TODO: respect trim flag after fixing #1685 * @param lineIndex line index the string was retrieved from * @param stringIndex index within the string * @param startCol column offset the string was retrieved from @@ -419,6 +420,7 @@ export class BufferStringIterator implements IBufferStringIterator { const range = this._buffer.getWrappedRangeForLine(this._current); let result = ''; for (let i = range.first; i <= range.last; ++i) { + // TODO: always apply trimRight after fixing #1685 result += this._buffer.translateBufferLineToString(i, (this._trimRight) ? i === range.last : false); } this._current = range.last;