This commit is contained in:
Daniel Imms
2019-01-23 22:48:32 -08:00
parent df7cd9c319
commit 178c513407
4 changed files with 23 additions and 69 deletions
-54
View File
@@ -5,58 +5,6 @@
import { BufferLine } from './BufferLine';
/**
* Determine how many lines need to be inserted at the end. This is done by finding what each
* wrapping point will be and counting the lines needed This would be a lot simpler but in the case
* of a line ending with a wide character, the wide character needs to be put on the following line
* or it would be cut in half.
* @param wrappedLines The original wrapped lines.
* @param newCols The new column count.
*/
export function reflowSmallerGetLinesNeeded(wrappedLines: BufferLine[], oldCols: number, newCols: number): number {
const lastLineLength = wrappedLines[wrappedLines.length - 1].getTrimmedLength();
// const cellsNeeded = (wrappedLines.length - 1) * this._cols + lastLineLength;
// TODO: Make faster
const cellsNeeded = wrappedLines.map(l => l.getTrimmedLength()).reduce((p, c) => p + c);
// Lines needed needs to take into account what the ending character of each new line is
let linesNeeded = 0;
let cellsAvailable = 0;
// let currentCol = 0;
// Use srcCol and srcLine to find the new wrapping point, use that to get the cellsAvailable and
// linesNeeded
let srcCol = -1;
let srcLine = 0;
while (cellsAvailable < cellsNeeded) {
// if (srcLine === wrappedLines.length - 1) {
// cellsAvailable += newCols;
// linesNeeded++;
// break;
// }
srcCol += newCols;
if (srcCol >= oldCols) {
srcCol -= oldCols;
srcLine++;
}
if (srcLine >= wrappedLines.length) {
linesNeeded++;
break;
}
const endsWithWide = wrappedLines[srcLine].getWidth(srcCol) === 2;
if (endsWithWide) {
srcCol--;
}
cellsAvailable += endsWithWide ? newCols - 1 : newCols;
linesNeeded++;
}
return linesNeeded;
// return Math.ceil(cellsNeeded / newCols);
}
/**
* Gets the new line lengths for a given wrapped line. The purpose of this function it to pre-
* compute the wrapping points since wide characters may need to be wrapped onto the following line.
@@ -74,8 +22,6 @@ export function reflowSmallerGetLinesNeeded(wrappedLines: BufferLine[], oldCols:
export function reflowSmallerGetNewLineLengths(wrappedLines: BufferLine[], oldCols: number, newCols: number): number[] {
const newLineLengths: number[] = [];
// TODO: Force cols = 2 to be minimum possible value, this will lock up
const cellsNeeded = wrappedLines.map(l => l.getTrimmedLength()).reduce((p, c) => p + c);
// Use srcCol and srcLine to find the new wrapping point, use that to get the cellsAvailable and