@@ -233,13 +233,14 @@ private class MultilineDisplayBlock : DisplayBlockBase
233233 { 
234234 internal  Collection < string >  ItemsToDisplay ; 
235235
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 ; 
237238
238239 public  void  DrawMultilineBlock ( ) 
239240 { 
240241 IConsole  console  =  Singleton . _console ; 
241242
242-  multilineItems  =  0 ; 
243+  extraPhysicalLines  =  0 ; 
243244
244245 SaveCursor ( ) ; 
245246 MoveCursorToStartDrawingPosition ( console ) ; 
@@ -251,16 +252,23 @@ public void DrawMultilineBlock()
251252 { 
252253 var  itemLength  =  LengthInBufferCells ( items [ index ] ) ; 
253254
255+  int  extra  =  0 ; 
254256 if  ( itemLength  >  bufferWidth ) 
255257 { 
256-  multilineItems  +=  itemLength  /  bufferWidth ; 
257- 
258+  extra  =  itemLength  /  bufferWidth ; 
258259 if  ( itemLength  %  bufferWidth  ==  0 ) 
259260 { 
260-  multilineItems -- ; 
261+  extra -- ; 
261262 } 
262263 } 
263264
265+  if  ( extra  >  0 ) 
266+  { 
267+  // Extra physical lines may cause buffer to scroll up. 
268+  AdjustForPossibleScroll ( extra ) ; 
269+  extraPhysicalLines  +=  extra ; 
270+  } 
271+ 
264272 console . Write ( items [ index ] ) ; 
265273
266274 // Explicit newline so consoles see each row as distinct lines, but skip the 
@@ -277,7 +285,7 @@ public void DrawMultilineBlock()
277285
278286 public  void  Clear ( ) 
279287 { 
280-  _singleton . WriteBlankLines ( Top ,  ItemsToDisplay . Count  +  multilineItems ) ; 
288+  _singleton . WriteBlankLines ( Top ,  ItemsToDisplay . Count  +  extraPhysicalLines ) ; 
281289 } 
282290 } 
283291 } 
0 commit comments