-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When the Terminal is resized, don't remove lines from scrollback #4354
Changes from all commits
b5c8c85
9aec694
1a2654d
aae6ce6
416be46
4319589
399b002
38ebbb6
c8c794f
ee08a5b
95122e3
17d25ee
668bad3
9ccc3bc
d116c6b
3398b19
2e9ebcc
c6a7e4e
872f4c4
f37ce01
252f466
02445fd
13c6171
48de202
3c4d157
c091471
c44bc9e
2fe6d8e
cd82017
26a16d4
f561f7f
8d855ed
7bae9ec
8c61481
4248c87
94559ed
be66829
715014d
8aa42f4
191952f
2d07816
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,14 +176,40 @@ void Terminal::UpdateSettings(winrt::Microsoft::Terminal::Settings::ICoreSetting | |
return S_FALSE; | ||
} | ||
|
||
const auto dy = viewportSize.Y - oldDimensions.Y; | ||
|
||
// We're going to attempt to "stick to the top" of where the old viewport was. | ||
const auto oldTop = _mutableViewport.Top(); | ||
|
||
const short newBufferHeight = viewportSize.Y + _scrollbackLines; | ||
COORD bufferSize{ viewportSize.X, newBufferHeight }; | ||
RETURN_IF_FAILED(_buffer->ResizeTraditional(bufferSize)); | ||
|
||
auto proposedTop = oldTop; | ||
const auto newView = Viewport::FromDimensions({ 0, proposedTop }, viewportSize); | ||
// However conpty resizes a little oddly - if the height decreased, and | ||
// there were blank lines at the bottom, those lines will get trimmed. | ||
// If there's not blank lines, then the top will get "shifted down", | ||
// moving the top line into scrollback. | ||
// See GH#3490 for more details. | ||
|
||
// If the final position in the buffer is on the bottom row of the new | ||
// viewport, then we're going to need to move the top down. Otherwise, | ||
// move the bottom up. | ||
const COORD cOldCursorPos = _buffer->GetCursor().GetPosition(); | ||
COORD cOldLastChar = cOldCursorPos; | ||
try | ||
{ | ||
cOldLastChar = _buffer->GetLastNonSpaceCharacter(); | ||
} | ||
CATCH_LOG(); | ||
|
||
const auto maxRow = std::max(cOldLastChar.Y, cOldCursorPos.Y); | ||
|
||
const bool beforeLastRow = maxRow < bufferSize.Y - 1; | ||
const auto adjustment = beforeLastRow ? 0 : std::max(0, -dy); | ||
|
||
auto proposedTop = oldTop + adjustment; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this math a candidate for the new |
||
|
||
const auto newView = Viewport::FromDimensions({ 0, gsl::narrow_cast<short>(proposedTop) }, viewportSize); | ||
const auto proposedBottom = newView.BottomExclusive(); | ||
// If the new bottom would be below the bottom of the buffer, then slide the | ||
// top up so that we'll still fit within the buffer. | ||
|
@@ -192,7 +218,8 @@ void Terminal::UpdateSettings(winrt::Microsoft::Terminal::Settings::ICoreSetting | |
proposedTop -= (proposedBottom - bufferSize.Y); | ||
} | ||
|
||
_mutableViewport = Viewport::FromDimensions({ 0, proposedTop }, viewportSize); | ||
_mutableViewport = Viewport::FromDimensions({ 0, gsl::narrow_cast<short>(proposedTop) }, viewportSize); | ||
|
||
_scrollOffset = 0; | ||
_NotifyScrollEvent(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hungarian