@@ -22,8 +22,8 @@ public class TerminalBuffer
2222 /// The absolute line index of the top of the viewport in the buffer.
2323 /// In XTerm.js this is 'ydisp'. This represents the current scroll position.
2424 /// </summary>
25- public int ViewportY
26- {
25+ public int ViewportY
26+ {
2727 get => _yDisp ;
2828 set => _yDisp = Math . Clamp ( value , 0 , _yBase ) ;
2929 }
@@ -144,20 +144,20 @@ public void ScrollUp(int lines, bool isWrapped = false)
144144 // When scrollTop is 0, the top line goes into scrollback.
145145 // In xterm.js: push new line first, then increment yBase and yDisp.
146146 // This causes the circular list to potentially recycle the oldest line.
147-
147+
148148 // Check if we're at max capacity - if so, yBase stays the same but
149149 // the buffer rotates. If not, yBase increments.
150150 var willBeRecycled = _lines . Length >= _lines . MaxLength ;
151-
151+
152152 // Push the new line at the end (bottom of screen in buffer terms)
153153 _lines . Push ( newLine ) ;
154-
154+
155155 // Only increment yBase if the buffer didn't recycle
156156 if ( ! willBeRecycled )
157157 {
158158 _yBase ++ ;
159159 }
160-
160+
161161 // If yDisp was at the bottom, keep it there
162162 if ( _yDisp + 1 < _yBase )
163163 {
@@ -348,9 +348,12 @@ public string PrintViewport()
348348 for ( int i = 0 ; i < _rows ; i ++ )
349349 {
350350 var line = GetLine ( _yDisp + i ) ;
351- foreach ( var cell in line )
351+ if ( line != null )
352352 {
353- sb . Append ( cell . Content ) ;
353+ foreach ( var cell in line )
354+ {
355+ sb . Append ( cell . Content ) ;
356+ }
354357 }
355358 sb . AppendLine ( ) ;
356359 }
0 commit comments