|
|
@@ -15,8 +15,16 @@ class ReflowStrategyNarrower extends ReflowStrategy {
|
|
|
final line = buffer.lines[i];
|
|
|
final lineLength = line.getTrimmedLength(oldCols);
|
|
|
if (lineLength > newCols) {
|
|
|
- final moveIndexStart = newCols;
|
|
|
- final cellsToCopy = oldCols - newCols;
|
|
|
+ var moveIndexStart = newCols;
|
|
|
+ var cellsToCopy = oldCols - 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
|
|
|
+ if (line.cellGetContent(moveIndexStart) == 0 &&
|
|
|
+ line.cellGetWidth(moveIndexStart - 1) == 2) {
|
|
|
+ moveIndexStart -= 1;
|
|
|
+ cellsToCopy += 1;
|
|
|
+ }
|
|
|
|
|
|
// 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
|
|
|
@@ -24,25 +32,24 @@ class ReflowStrategyNarrower extends ReflowStrategy {
|
|
|
if (i + 1 < buffer.lines.length) {
|
|
|
final nextLine = buffer.lines[i + 1];
|
|
|
if (nextLine.isWrapped) {
|
|
|
- nextLine.ensure(oldCols + cellsToCopy);
|
|
|
+ nextLine.ensure(oldCols + cellsToCopy); //to be safe
|
|
|
nextLine.insertN(0, cellsToCopy);
|
|
|
nextLine.copyCellsFrom(line, moveIndexStart, 0, cellsToCopy);
|
|
|
+ // clean the cells that we moved
|
|
|
line.erase(buffer.terminal.cursor, moveIndexStart, oldCols);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
final newLine = BufferLine(isWrapped: true);
|
|
|
- newLine.ensure(newCols);
|
|
|
+ newLine.ensure(max(newCols, cellsToCopy));
|
|
|
newLine.copyCellsFrom(line, moveIndexStart, 0, cellsToCopy);
|
|
|
+ // clean the cells that we moved
|
|
|
line.erase(buffer.terminal.cursor, moveIndexStart, oldCols);
|
|
|
|
|
|
- //TODO: aggregate and do at the end?
|
|
|
buffer.lines.insert(i + 1, newLine);
|
|
|
|
|
|
- if (i + 1 <= buffer.cursorY) {
|
|
|
- buffer.moveCursorY(1);
|
|
|
- }
|
|
|
+ //TODO: scrolling is a bit weird afterwards
|
|
|
}
|
|
|
}
|
|
|
}
|