|
|
@@ -11,12 +11,13 @@ class ReflowStrategyNarrower extends ReflowStrategy {
|
|
|
|
|
|
@override
|
|
|
void reflow(int newCols, int newRows, int oldCols, int oldRows) {
|
|
|
+ //print('Reflow narrower $oldCols -> $newCols');
|
|
|
for (var i = 0; i < buffer.lines.length; i++) {
|
|
|
final line = buffer.lines[i];
|
|
|
- final lineLength = line.getTrimmedLength(oldCols);
|
|
|
+ final lineLength = line.getTrimmedLength();
|
|
|
if (lineLength > newCols) {
|
|
|
var moveIndexStart = newCols;
|
|
|
- var cellsToCopy = oldCols - newCols;
|
|
|
+ var cellsToCopy = lineLength - newCols;
|
|
|
|
|
|
// when we have a double width character and are about to move the "0" placeholder,
|
|
|
// then we have to move the double width character as well
|
|
|
@@ -26,17 +27,28 @@ class ReflowStrategyNarrower extends ReflowStrategy {
|
|
|
cellsToCopy += 1;
|
|
|
}
|
|
|
|
|
|
+ var addZero = false;
|
|
|
+ //when the last cell to copy is a double width cell, then add a "0"
|
|
|
+ if (line.cellGetWidth(moveIndexStart + cellsToCopy - 1) == 2) {
|
|
|
+ addZero = true;
|
|
|
+ }
|
|
|
+
|
|
|
// we need to move cut cells to the next line
|
|
|
// if the next line is wrapped anyway, we can push them onto the beginning of that line
|
|
|
// otherwise, we need add a new wrapped line
|
|
|
if (i + 1 < buffer.lines.length) {
|
|
|
final nextLine = buffer.lines[i + 1];
|
|
|
if (nextLine.isWrapped) {
|
|
|
- nextLine.ensure(oldCols + cellsToCopy); //to be safe
|
|
|
- nextLine.insertN(0, cellsToCopy);
|
|
|
+ final nextLineLength = nextLine.getTrimmedLength();
|
|
|
+ nextLine.ensure(nextLineLength + cellsToCopy + (addZero ? 1 : 0));
|
|
|
+ nextLine.insertN(0, cellsToCopy + (addZero ? 1 : 0));
|
|
|
nextLine.copyCellsFrom(line, moveIndexStart, 0, cellsToCopy);
|
|
|
// clean the cells that we moved
|
|
|
- line.erase(buffer.terminal.cursor, moveIndexStart, oldCols);
|
|
|
+ line.erase(buffer.terminal.cursor, moveIndexStart,
|
|
|
+ moveIndexStart + cellsToCopy);
|
|
|
+ //print('M: ${i < 10 ? '0' : ''}$i: ${line.toDebugString(oldCols)}');
|
|
|
+ //print(
|
|
|
+ // 'N: ${i + 1 < 10 ? '0' : ''}${i + 1}: ${nextLine.toDebugString(oldCols)}');
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
@@ -45,11 +57,15 @@ class ReflowStrategyNarrower extends ReflowStrategy {
|
|
|
newLine.ensure(max(newCols, cellsToCopy));
|
|
|
newLine.copyCellsFrom(line, moveIndexStart, 0, cellsToCopy);
|
|
|
// clean the cells that we moved
|
|
|
- line.erase(buffer.terminal.cursor, moveIndexStart, oldCols);
|
|
|
+ line.erase(buffer.terminal.cursor, moveIndexStart, lineLength);
|
|
|
|
|
|
buffer.lines.insert(i + 1, newLine);
|
|
|
|
|
|
//TODO: scrolling is a bit weird afterwards
|
|
|
+
|
|
|
+ //print('S: ${i < 10 ? '0' : ''}$i: ${line.toDebugString(oldCols)}');
|
|
|
+ } else {
|
|
|
+ //print('N: ${i < 10 ? '0' : ''}$i: ${line.toDebugString(oldCols)}');
|
|
|
}
|
|
|
}
|
|
|
}
|