@@ -233,13 +233,14 @@ private class MultilineDisplayBlock : DisplayBlockBase
233
233
{
234
234
internal Collection < string > ItemsToDisplay ;
235
235
236
- private int multilineItems = 0 ;
236
+ // Keep track of the number of extra physical lines due to multi-line text.
237
+ private int extraPhysicalLines = 0 ;
237
238
238
239
public void DrawMultilineBlock ( )
239
240
{
240
241
IConsole console = Singleton . _console ;
241
242
242
- multilineItems = 0 ;
243
+ extraPhysicalLines = 0 ;
243
244
244
245
SaveCursor ( ) ;
245
246
MoveCursorToStartDrawingPosition ( console ) ;
@@ -251,16 +252,23 @@ public void DrawMultilineBlock()
251
252
{
252
253
var itemLength = LengthInBufferCells ( items [ index ] ) ;
253
254
255
+ int extra = 0 ;
254
256
if ( itemLength > bufferWidth )
255
257
{
256
- multilineItems += itemLength / bufferWidth ;
257
-
258
+ extra = itemLength / bufferWidth ;
258
259
if ( itemLength % bufferWidth == 0 )
259
260
{
260
- multilineItems -- ;
261
+ extra -- ;
261
262
}
262
263
}
263
264
265
+ if ( extra > 0 )
266
+ {
267
+ // Extra physical lines may cause buffer to scroll up.
268
+ AdjustForPossibleScroll ( extra ) ;
269
+ extraPhysicalLines += extra ;
270
+ }
271
+
264
272
console . Write ( items [ index ] ) ;
265
273
266
274
// Explicit newline so consoles see each row as distinct lines, but skip the
@@ -277,7 +285,7 @@ public void DrawMultilineBlock()
277
285
278
286
public void Clear ( )
279
287
{
280
- _singleton . WriteBlankLines ( Top , ItemsToDisplay . Count + multilineItems ) ;
288
+ _singleton . WriteBlankLines ( Top , ItemsToDisplay . Count + extraPhysicalLines ) ;
281
289
}
282
290
}
283
291
}
0 commit comments