diff --git a/src/terminal/adapter/PageManager.cpp b/src/terminal/adapter/PageManager.cpp index 39f97a12b8ae..dbd0f3a1244c 100644 --- a/src/terminal/adapter/PageManager.cpp +++ b/src/terminal/adapter/PageManager.cpp @@ -104,20 +104,29 @@ Page PageManager::Get(const til::CoordType pageNumber) const { const auto requestedPageNumber = std::min(std::max(pageNumber, 1), MAX_PAGES); auto [visibleBuffer, visibleViewport, isMainBuffer] = _api.GetBufferAndViewport(); + + // If we're not in the main buffer (either because an app has enabled the + // alternate buffer mode, or switched the conhost screen buffer), then VT + // paging doesn't apply, so we disregard the requested page number and just + // use the visible buffer (with a fixed page number of 1). if (!isMainBuffer) { return { visibleBuffer, visibleViewport, 1 }; } - else if (requestedPageNumber == _visiblePageNumber) + + // If the requested page number happens to be the visible page, then we + // can also just use the visible buffer as is. + if (requestedPageNumber == _visiblePageNumber) { return { visibleBuffer, visibleViewport, _visiblePageNumber }; } - else - { - const auto pageSize = visibleViewport.size(); - auto& pageBuffer = _getBuffer(requestedPageNumber, pageSize); - return { pageBuffer, til::rect{ pageSize }, requestedPageNumber }; - } + + // Otherwise we're working with a background buffer, so we need to + // retrieve that from the buffer array, and resize it to match the + // active page size. + const auto pageSize = visibleViewport.size(); + auto& pageBuffer = _getBuffer(requestedPageNumber, pageSize); + return { pageBuffer, til::rect{ pageSize }, requestedPageNumber }; } Page PageManager::ActivePage() const