Procházet zdrojové kódy

fixes resizing of non-active buffer

devmil před 4 roky
rodič
revize
0b5dcd9508

+ 6 - 2
lib/buffer/buffer.dart

@@ -10,7 +10,10 @@ import 'package:xterm/util/scroll_range.dart';
 import 'package:xterm/util/unicode_v11.dart';
 
 class Buffer {
-  Buffer(this.terminal) {
+  Buffer({
+    required this.terminal,
+    required this.isAltBuffer,
+  }) {
     resetVerticalMargins();
 
     lines = CircularList(
@@ -22,6 +25,7 @@ class Buffer {
   }
 
   final Terminal terminal;
+  final bool isAltBuffer;
   final charset = Charset();
 
   /// lines of the buffer. the length of [lines] should always be equal or
@@ -524,7 +528,7 @@ class Buffer {
     _cursorX = _cursorX.clamp(0, newWidth - 1);
     _cursorY = _cursorY.clamp(0, newHeight - 1);
 
-    if (!terminal.isUsingAltBuffer()) {
+    if (!isAltBuffer) {
       final reflowStrategy = newWidth > oldWidth
           ? ReflowStrategyWider(this)
           : ReflowStrategyNarrower(this);

+ 3 - 0
lib/buffer/buffer_line.dart

@@ -147,6 +147,9 @@ class BufferLine {
   }
 
   int cellGetContent(int index) {
+    if (index > _maxCols) {
+      return 0;
+    }
     return _cells.getUint32(index * _cellSize + _cellContent);
   }
 

+ 5 - 3
lib/terminal/terminal.dart

@@ -44,8 +44,8 @@ class Terminal with Observable implements TerminalUiInteraction {
   }) : _maxLines = maxLines {
     backend?.init();
     backend?.out.listen(write);
-    _mainBuffer = Buffer(this);
-    _altBuffer = Buffer(this);
+    _mainBuffer = Buffer(terminal: this, isAltBuffer: false);
+    _altBuffer = Buffer(terminal: this, isAltBuffer: true);
     _buffer = _mainBuffer;
 
     cursor = Cursor(
@@ -362,7 +362,9 @@ class Terminal with Observable implements TerminalUiInteraction {
     _viewWidth = newWidth;
     _viewHeight = newHeight;
 
-    buffer.resize(oldWidth, oldHeight, newWidth, newHeight);
+    //we need to resize both buffers so that they are ready when we switch between them
+    _altBuffer.resize(oldWidth, oldHeight, newWidth, newHeight);
+    _mainBuffer.resize(oldWidth, oldHeight, newWidth, newHeight);
 
     // maybe reflow should happen here.
     if (buffer == _altBuffer) {