Automatic scrolling of window when setting cursor position
#14.774 geöffnet am 2. Feb. 2023
Repository-Metriken
- Stars
- (35.764 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 27T 19h) (24 gemergte PRs in 30 T)
Beschreibung
Windows Terminal version
1.16.230126001
Windows build number
10.0.19044.2486
Other Software
No response
Steps to reproduce
I mentioned this first in #14759.
You can reproduce the problem with this test program:
#include <windows.h>
int main()
{
HANDLE con = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(con, &csbi);
// use scrollback of 100 lines
COORD con_size = {
csbi.srWindow.Right - csbi.srWindow.Left + 1,
csbi.srWindow.Bottom - csbi.srWindow.Top + 1 + 100
};
SetConsoleScreenBufferSize(con, con_size);
// write 50 lines so the position is not at the top of the scrollback
for (int i = 0; i < 50; i++)
WriteConsoleA(con, "line\n", 5, NULL, NULL);
// stop at escape key
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
INPUT_RECORD ir;
DWORD didread;
while (ReadConsoleInput(in, &ir, 1, &didread))
{
if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown)
{
if (ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
break;
WriteConsoleA(con, &ir.Event.KeyEvent.uChar.AsciiChar, 1, NULL, NULL);
GetConsoleScreenBufferInfo(con, &csbi);
// re-set the cursor position where it already is, this is done
// so the cursor is visible at the new location after the character
// was printed
SetConsoleCursorPosition(con, csbi.dwCursorPosition);
// now the console window is scrolled so that the cursor is at the bottom
// of the window.
}
}
return 0;
}
There is a difference of behavior when tried with either the conhost.exe of the current Win10, or the OpenConsole.exe of Microsoft.WindowsTerminal_Win10_1.16.10261.0_8wekyb3d8bbwe.msixbundle.
Between entering some keys, scroll the window up or down with the mouse.
Expected Behavior
Once you enter a key, and the cursor position is re-set, it will scroll the window to the cursor, but only if the cursor was not already in the visible part of the window. Which is exactly how it works in conhost.exe.
Actual Behavior
But with OpenConsole.exe 1.16.230126001, the window is always scrolled so that the cursor is at the bottom of the screen, even if it was already visible before.