cleanup
This commit is contained in:
+1
-2
@@ -508,11 +508,10 @@ describe('Buffer', () => {
|
|||||||
// the dangling last cell is wrongly added in the string
|
// the dangling last cell is wrongly added in the string
|
||||||
// --> fixable after resolving #1685
|
// --> fixable after resolving #1685
|
||||||
terminal.writeSync(input);
|
terminal.writeSync(input);
|
||||||
// TODO: reenable after fix
|
|
||||||
const s = terminal.buffer.iterator(true).next().content;
|
const s = terminal.buffer.iterator(true).next().content;
|
||||||
assert.equal(input, s);
|
assert.equal(input, s);
|
||||||
for (let i = 10; i < input.length; ++i) {
|
for (let i = 10; i < input.length; ++i) {
|
||||||
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i); // TODO: remove +1 after fix
|
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i);
|
||||||
const j = (i - 0) << 1;
|
const j = (i - 0) << 1;
|
||||||
assert.deepEqual([(j / terminal.cols) | 0, j % terminal.cols], bufferIndex);
|
assert.deepEqual([(j / terminal.cols) | 0, j % terminal.cols], bufferIndex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -271,65 +271,11 @@ export class Buffer implements IBuffer {
|
|||||||
* @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 = null): string {
|
||||||
// Get full line
|
|
||||||
let lineString = '';
|
|
||||||
const line = this.lines.get(lineIndex);
|
const line = this.lines.get(lineIndex);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return line.translateToString(trimRight, startCol, endCol);
|
return line.translateToString(trimRight, startCol, endCol);
|
||||||
|
|
||||||
// Initialize column and index values. Column values represent the actual
|
|
||||||
// cell column, indexes represent the index in the string. Indexes are
|
|
||||||
// needed here because some chars are 0 characters long (eg. after wide
|
|
||||||
// chars) and some chars are longer than 1 characters long (eg. emojis).
|
|
||||||
let startIndex = startCol;
|
|
||||||
// Only set endCol to the line length when it is null. 0 is a valid column.
|
|
||||||
if (endCol === null) {
|
|
||||||
endCol = line.length;
|
|
||||||
}
|
|
||||||
let endIndex = endCol;
|
|
||||||
|
|
||||||
for (let i = 0; i < line.length; i++) {
|
|
||||||
const char = line.get(i);
|
|
||||||
lineString += char[CHAR_DATA_CHAR_INDEX];
|
|
||||||
// Adjust start and end cols for wide characters if they affect their
|
|
||||||
// column indexes
|
|
||||||
if (char[CHAR_DATA_WIDTH_INDEX] === 0) {
|
|
||||||
if (startCol >= i) {
|
|
||||||
startIndex--;
|
|
||||||
}
|
|
||||||
if (endCol > i) {
|
|
||||||
endIndex--;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Adjust the columns to take glyphs that are represented by multiple
|
|
||||||
// code points into account.
|
|
||||||
if (char[CHAR_DATA_CHAR_INDEX].length > 1) {
|
|
||||||
if (startCol > i) {
|
|
||||||
startIndex += char[CHAR_DATA_CHAR_INDEX].length - 1;
|
|
||||||
}
|
|
||||||
if (endCol > i) {
|
|
||||||
endIndex += char[CHAR_DATA_CHAR_INDEX].length - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the final end col by trimming whitespace on the right of the
|
|
||||||
// line if needed.
|
|
||||||
if (trimRight) {
|
|
||||||
const rightWhitespaceIndex = lineString.search(/\s+$/);
|
|
||||||
if (rightWhitespaceIndex !== -1) {
|
|
||||||
endIndex = Math.min(endIndex, rightWhitespaceIndex);
|
|
||||||
}
|
|
||||||
// Return the empty string if only trimmed whitespace is selected
|
|
||||||
if (endIndex <= startIndex) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lineString.substring(startIndex, endIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getWrappedRangeForLine(y: number): { first: number, last: number } {
|
public getWrappedRangeForLine(y: number): { first: number, last: number } {
|
||||||
|
|||||||
+7
-4
@@ -143,6 +143,9 @@ const enum Cell {
|
|||||||
WIDTH = 2
|
WIDTH = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** single vs. combined char distinction */
|
||||||
|
const COMBINED = 0x80000000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Typed array based bufferline implementation.
|
* Typed array based bufferline implementation.
|
||||||
* Note: Unlike the JS variant the access to the data
|
* Note: Unlike the JS variant the access to the data
|
||||||
@@ -177,11 +180,11 @@ export class BufferLineTypedArray implements IBufferLine {
|
|||||||
const stringData = this._data[index * CELL_SIZE + Cell.STRING];
|
const stringData = this._data[index * CELL_SIZE + Cell.STRING];
|
||||||
return [
|
return [
|
||||||
this._data[index * CELL_SIZE + Cell.FLAGS],
|
this._data[index * CELL_SIZE + Cell.FLAGS],
|
||||||
(stringData & 0x80000000)
|
(stringData & COMBINED)
|
||||||
? this._combined[index]
|
? this._combined[index]
|
||||||
: (stringData) ? String.fromCharCode(stringData) : '',
|
: (stringData) ? String.fromCharCode(stringData) : '',
|
||||||
this._data[index * CELL_SIZE + Cell.WIDTH],
|
this._data[index * CELL_SIZE + Cell.WIDTH],
|
||||||
(stringData & 0x80000000)
|
(stringData & COMBINED)
|
||||||
? this._combined[index].charCodeAt(this._combined[index].length - 1)
|
? this._combined[index].charCodeAt(this._combined[index].length - 1)
|
||||||
: stringData
|
: stringData
|
||||||
];
|
];
|
||||||
@@ -191,7 +194,7 @@ export class BufferLineTypedArray implements IBufferLine {
|
|||||||
this._data[index * CELL_SIZE + Cell.FLAGS] = value[0];
|
this._data[index * CELL_SIZE + Cell.FLAGS] = value[0];
|
||||||
if (value[1].length > 1) {
|
if (value[1].length > 1) {
|
||||||
this._combined[index] = value[1];
|
this._combined[index] = value[1];
|
||||||
this._data[index * CELL_SIZE + Cell.STRING] = index | 0x80000000;
|
this._data[index * CELL_SIZE + Cell.STRING] = index | COMBINED;
|
||||||
} else {
|
} else {
|
||||||
this._data[index * CELL_SIZE + Cell.STRING] = value[1].charCodeAt(0);
|
this._data[index * CELL_SIZE + Cell.STRING] = value[1].charCodeAt(0);
|
||||||
}
|
}
|
||||||
@@ -320,7 +323,7 @@ export class BufferLineTypedArray implements IBufferLine {
|
|||||||
let result = '';
|
let result = '';
|
||||||
while (startCol < length) {
|
while (startCol < length) {
|
||||||
const stringData = this._data[startCol * CELL_SIZE + Cell.STRING];
|
const stringData = this._data[startCol * CELL_SIZE + Cell.STRING];
|
||||||
result += (stringData & 0x80000000) ? this._combined[startCol] : (stringData) ? String.fromCharCode(stringData) : ' ';
|
result += (stringData & COMBINED) ? this._combined[startCol] : (stringData) ? String.fromCharCode(stringData) : ' ';
|
||||||
startCol += this._data[startCol * CELL_SIZE + Cell.WIDTH] || 1;
|
startCol += this._data[startCol * CELL_SIZE + Cell.WIDTH] || 1;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
Reference in New Issue
Block a user