Repository: microsoft/terminal (language: cpp)

Issue:
After clearing the screen (cls command) and then scrolling up, results in the last line of the previous screen still visible
### Windows Terminal version

1.13.11432.0

### Windows build number

10.0.22000.739

### Other Software

_No response_

### Steps to reproduce

1. Open Terminal
2. Navigate to `C:\Windows\System32`, a folder where files are available in large numbers so that results occupy an almost available screen space
3. First run the `dir` command so that Terminal is made use of
4. Now clear the screen using the `cls` command
5. Now try to scroll up, the last line of the previous screen is still visible

### Expected Behavior

When cleared nothing should be visible from the previous result.

### Actual Behavior

When scrolled upwards, the last line is still visible even after clearing the results.


Discussion / hints:
I suspect this might be the same problem as #5770.

Fix patch:
diff --git a/src/host/_output.cpp b/src/host/_output.cpp
index cba5626219a..38b5a66f65e 100644
--- a/src/host/_output.cpp
+++ b/src/host/_output.cpp
@@ -315,6 +315,9 @@ void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region)
 
             if (wroteWholeBuffer && startedAtOrigin && wroteSpaces)
             {
+                // It's important that we flush the renderer at this point so we don't
+                // have any pending output rendered after the scrollback is cleared.
+                ServiceLocator::LocateGlobals().pRender->TriggerFlush(false);
                 hr = gci.GetVtIo()->ManuallyClearScrollback();
             }
         }
diff --git a/src/host/getset.cpp b/src/host/getset.cpp
index b72259da01f..db84deff8dc 100644
--- a/src/host/getset.cpp
+++ b/src/host/getset.cpp
@@ -971,6 +971,9 @@ void ApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& cont
 
             if (sourceIsWholeBuffer && targetIsNegativeBufferHeight && noClipProvided && fillIsBlank)
             {
+                // It's important that we flush the renderer at this point so we don't
+                // have any pending output rendered after the scrollback is cleared.
+                ServiceLocator::LocateGlobals().pRender->TriggerFlush(false);
                 hr = gci.GetVtIo()->ManuallyClearScrollback();
             }
         }


Test patch: