Просмотр исходного кода

emojis work in principal. Fast size change leads to strange effects

devmil 4 лет назад
Родитель
Сommit
50e49fbbcf
2 измененных файлов с 26 добавлено и 16 удалено
  1. 15 8
      lib/buffer/reflow_strategy_narrower.dart
  2. 11 8
      lib/buffer/reflow_strategy_wider.dart

+ 15 - 8
lib/buffer/reflow_strategy_narrower.dart

@@ -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
       }
     }
   }

+ 11 - 8
lib/buffer/reflow_strategy_wider.dart

@@ -24,13 +24,17 @@ class ReflowStrategyWider extends ReflowStrategy {
           break;
         }
         final nextLineLength = nextLine.getTrimmedLength(oldCols);
-        final moveCount = min(spaceOnLine, nextLineLength);
+        var moveCount = min(spaceOnLine, nextLineLength);
+
+        // when we are about to copy a double width character
+        // to the end of the line then we can include the 0 width placeholder
+        // after it
+        if (nextLine.cellGetWidth(moveCount - 1) == 2 &&
+            nextLine.cellGetContent(moveCount) == 0) {
+          moveCount += 1;
+        }
         line.copyCellsFrom(nextLine, 0, lineLength, moveCount);
-        if (moveCount == nextLineLength) {
-          if (i + offset <= buffer.cursorY) {
-            //TODO: adapt scrolling
-            buffer.moveCursorY(-1);
-          }
+        if (moveCount >= nextLineLength) {
           // if we unwrapped all cells off the next line, delete it
           buffer.lines.remove(i + offset);
           offset--;
@@ -41,8 +45,7 @@ class ReflowStrategyWider extends ReflowStrategy {
       }
     }
     //buffer doesn't have enough lines
-    if (buffer.lines.length < buffer.terminal.viewHeight) {
-      // Add an extra row at the bottom of the viewport
+    while (buffer.lines.length < buffer.terminal.viewHeight) {
       buffer.lines.push(BufferLine());
     }
   }