Fix clear screen behaviour of console when user scrolled up or down

We must call SetConsoleCursorPosition prior to SetConsoleWindowInfo,
otherwise the scroll bars will not be updated by the OS.  Make sure
to scroll the console window by just the right amount to have the
new cursor position one line after the used console buffer area at
the top of the console window, no matter the scroll state.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2016-07-29 12:07:46 +02:00
parent 08da3bfc41
commit d7586cb66c
1 changed files with 21 additions and 1 deletions

View File

@ -1248,7 +1248,16 @@ dev_console::scroll_window (HANDLE h, int x1, int y1, int x2, int y2)
else
{
/* The reminder of the console buffer is big enough to simply move
the console window. */
the console window. We have to set the cursor first, otherwise
the scroll bars will not be corrected. */
SetConsoleCursorPosition (h, dwEnd);
/* If we scroll backwards, setting the cursor position will scroll
the console window up so that the cursor is at the bottom. Correct
the action by moving the window down again so the cursor is one line
above the new window position. */
if (toscroll < 0)
toscroll = b.srWindow.Bottom - b.srWindow.Top;
/* Move the window accordingly. */
sr.Top = sr.Bottom = toscroll;
SetConsoleWindowInfo (h, FALSE, &sr);
}
@ -1268,6 +1277,8 @@ void __reg3
fhandler_console::clear_screen (cltype xc1, cltype yc1, cltype xc2, cltype yc2)
{
HANDLE h = get_output_handle ();
SHORT oldEndY = con.dwEnd.Y;
con.fillin (h);
int x1 = con.set_cl_x (xc1);
@ -1275,6 +1286,15 @@ fhandler_console::clear_screen (cltype xc1, cltype yc1, cltype xc2, cltype yc2)
int x2 = con.set_cl_x (xc2);
int y2 = con.set_cl_y (yc2);
/* Make correction for the following situation: The console buffer
is only partially used and the user scrolled down into the as yet
unused area. */
if (oldEndY < con.dwEnd.Y)
{
con.dwEnd.Y = con.b.dwCursorPosition.Y = oldEndY;
y1 = con.b.srWindow.Top;
}
/* Detect special case - scroll the screen if we have a buffer in order to
preserve the buffer. */
if (!con.scroll_window (h, x1, y1, x2, y2))