translateToString() adds one more entry to outColumns

Previously, for string 'ab好', outColumns=[0, 1, 2]. Now it becomes [0,
1, 2, 4]. This allows the user to know where does the last character
ends.
This commit is contained in:
Jason Lin
2023-10-11 16:23:03 +11:00
parent 1b940de0bf
commit c3aa63cffa
3 changed files with 41 additions and 35 deletions
+10 -4
View File
@@ -510,10 +510,13 @@ export class BufferLine implements IBufferLine {
/**
* If outColumns is specified, it will be filled with column numbers such that
* returnedString[i] is display at outColumns[i] column. When a single cell is
* translated to multiple UTF-16 code units (e.g. surrogate pair) in the
* returned string, the corresponding entries in outColumns will have the same
* column number.
* returnedString[i] is display at outColumns[i] column.
* outColumns[returnedString.length] is where the character following
* returnedString will be displayed.
*
* When a single cell is translated to multiple UTF-16 code units (e.g.
* surrogate pair) in the returned string, the corresponding entries in
* outColumns will have the same column number.
*/
public translateToString(trimRight?: boolean, startCol?: number, endCol?: number, outColumns?: number[]): string {
startCol = startCol ?? 0;
@@ -537,6 +540,9 @@ export class BufferLine implements IBufferLine {
}
startCol += (content >> Content.WIDTH_SHIFT) || 1; // always advance by at least 1
}
if (outColumns) {
outColumns.push(startCol);
}
return result;
}
}