Skip to content

Commit b968f91

Browse files
committed
PRE-MERGE microsoft#17143 Improve Viewport and Viewport::WalkInBounds
2 parents 5460324 + ee6af59 commit b968f91

File tree

19 files changed

+65
-601
lines changed

19 files changed

+65
-601
lines changed

src/buffer/out/textBuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ const til::CoordType TextBuffer::GetFirstRowIndex() const noexcept
993993

994994
const Viewport TextBuffer::GetSize() const noexcept
995995
{
996-
return Viewport::FromDimensions({ _width, _height });
996+
return Viewport::FromDimensions({}, { _width, _height });
997997
}
998998

999999
void TextBuffer::_SetFirstRowIndex(const til::CoordType FirstRowIndex) noexcept
@@ -1597,7 +1597,7 @@ til::point TextBuffer::_GetWordEndForSelection(const til::point target, const st
15971597
}
15981598
}
15991599

1600-
bufferSize.IncrementInBoundsCircular(result);
1600+
bufferSize.IncrementInBounds(result);
16011601
}
16021602

16031603
if (_GetDelimiterClassAt(result, wordDelimiters) != initialDelimiter)

src/cascadia/TerminalControl/ControlCore.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,21 +2645,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
26452645
// Select the region of text between [s.start, s.end), in buffer space
26462646
void ControlCore::_selectSpan(til::point_span s)
26472647
{
2648-
// s.end is an _exclusive_ point. We need an inclusive one. But
2649-
// decrement in bounds wants an inclusive one. If you pass an exclusive
2650-
// one, then it might assert at you for being out of bounds. So we also
2651-
// take care of the case that the end point is outside the viewport
2652-
// manually.
2648+
// s.end is an _exclusive_ point. We need an inclusive one.
26532649
const auto bufferSize{ _terminal->GetTextBuffer().GetSize() };
26542650
til::point inclusiveEnd = s.end;
2655-
if (s.end.x == bufferSize.Width())
2656-
{
2657-
inclusiveEnd = til::point{ std::max(0, s.end.x - 1), s.end.y };
2658-
}
2659-
else
2660-
{
2661-
bufferSize.DecrementInBounds(inclusiveEnd);
2662-
}
2651+
bufferSize.DecrementInBounds(inclusiveEnd);
26632652

26642653
_terminal->SelectNewRegion(s.start, inclusiveEnd);
26652654
_renderer->TriggerSelection();

src/cascadia/TerminalControl/HwndTerminal.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ HRESULT HwndTerminal::Refresh(const til::size windowSize, _Out_ til::size* dimen
356356
_renderer->TriggerRedrawAll();
357357

358358
// Convert our new dimensions to characters
359-
const auto viewInPixels = Viewport::FromDimensions(windowSize);
359+
const auto viewInPixels = Viewport::FromDimensions({}, windowSize);
360360
const auto vp = _renderEngine->GetViewportInCharacters(viewInPixels);
361361

362362
// Guard against resizing the window to 0 columns/rows, which the text buffer classes don't really support.
@@ -464,7 +464,7 @@ try
464464

465465
Viewport viewInPixels;
466466
{
467-
const auto viewInCharacters = Viewport::FromDimensions(dimensionsInCharacters);
467+
const auto viewInCharacters = Viewport::FromDimensions({}, dimensionsInCharacters);
468468
const auto lock = publicTerminal->_terminal->LockForReading();
469469
viewInPixels = publicTerminal->_renderEngine->GetViewportInPixels(viewInCharacters);
470470
}
@@ -491,7 +491,7 @@ try
491491
{
492492
const auto publicTerminal = static_cast<const HwndTerminal*>(terminal);
493493

494-
const auto viewInPixels = Viewport::FromDimensions({ width, height });
494+
const auto viewInPixels = Viewport::FromDimensions({}, { width, height });
495495
const auto lock = publicTerminal->_terminal->LockForReading();
496496
const auto viewInCharacters = publicTerminal->_renderEngine->GetViewportInCharacters(viewInPixels);
497497

src/cascadia/TerminalCore/Terminal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ Viewport Terminal::_GetMutableViewport() const noexcept
961961
// GH#3493: if we're in the alt buffer, then it's possible that the mutable
962962
// viewport's size hasn't been updated yet. In that case, use the
963963
// temporarily stashed _altBufferSize instead.
964-
return _inAltBuffer() ? Viewport::FromDimensions(_altBufferSize) :
964+
return _inAltBuffer() ? Viewport::FromDimensions({}, _altBufferSize) :
965965
_mutableViewport;
966966
}
967967

src/cascadia/TerminalCore/TerminalSelection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void Terminal::SelectHyperlink(const SearchDirection dir)
495495
searchEnd = { bufferSize.RightInclusive(), searchStart.y - 1 };
496496
searchStart = { bufferSize.Left(), std::max(searchStart.y - viewportHeight, bufferSize.Top()) };
497497
}
498-
searchArea = Viewport::FromDimensions(searchStart, searchEnd.x + 1, searchEnd.y + 1);
498+
searchArea = Viewport::FromDimensions(searchStart, { searchEnd.x + 1, searchEnd.y + 1 });
499499

500500
const til::point bufferStart{ bufferSize.Origin() };
501501
const til::point bufferEnd{ bufferSize.RightInclusive(), ViewEndIndex() };
@@ -516,7 +516,7 @@ void Terminal::SelectHyperlink(const SearchDirection dir)
516516
searchEnd.y -= 1;
517517
searchStart.y = std::max(searchEnd.y - viewportHeight, bufferSize.Top());
518518
}
519-
searchArea = Viewport::FromDimensions(searchStart, searchEnd.x + 1, searchEnd.y + 1);
519+
searchArea = Viewport::FromDimensions(searchStart, { searchEnd.x + 1, searchEnd.y + 1 });
520520
}
521521
}
522522

src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,13 +4873,7 @@ void ConptyRoundtripTests::ReflowPromptRegions()
48734873
til::point afterPos = originalPos;
48744874
// walk that original pos dx times into the actual real place in the buffer.
48754875
auto bufferViewport = tb.GetSize();
4876-
const auto walkDir = Viewport::WalkDir{ dx < 0 ? Viewport::XWalk::LeftToRight : Viewport::XWalk::RightToLeft,
4877-
dx < 0 ? Viewport::YWalk::TopToBottom : Viewport::YWalk::BottomToTop };
4878-
for (auto i = 0; i < std::abs(dx); i++)
4879-
{
4880-
bufferViewport.WalkInBounds(afterPos,
4881-
walkDir);
4882-
}
4876+
bufferViewport.WalkInBounds(afterPos, -dx);
48834877
const auto expectedOutputStart = !afterResize ?
48844878
originalPos : // printed exactly a row, so we're exactly below the prompt
48854879
afterPos;

src/host/VtIo.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ VtIo::VtIo() :
150150

151151
if (IsValidHandle(_hOutput.get()))
152152
{
153-
auto initialViewport = Viewport::FromDimensions({ 0, 0 },
154-
gci.GetWindowSize().width,
155-
gci.GetWindowSize().height);
153+
auto initialViewport = Viewport::FromDimensions({ 0, 0 }, gci.GetWindowSize());
156154
switch (_IoMode)
157155
{
158156
case VtIoMode::XTERM_256:

src/host/_output.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region)
223223
{
224224
// Notify accessibility
225225
auto endingCoordinate = startingCoordinate;
226-
bufferSize.MoveInBounds(cellsModifiedCoord, endingCoordinate);
226+
bufferSize.WalkInBounds(endingCoordinate, cellsModifiedCoord);
227227
screenBuffer.NotifyAccessibilityEventing(startingCoordinate.x, startingCoordinate.y, endingCoordinate.x, endingCoordinate.y);
228228
}
229229
}
@@ -287,7 +287,7 @@ void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region)
287287
if (screenInfo.HasAccessibilityEventing())
288288
{
289289
auto endingCoordinate = startingCoordinate;
290-
bufferSize.MoveInBounds(cellsModifiedCoord, endingCoordinate);
290+
bufferSize.WalkInBounds(endingCoordinate, cellsModifiedCoord);
291291
screenInfo.NotifyAccessibilityEventing(startingCoordinate.x, startingCoordinate.y, endingCoordinate.x, endingCoordinate.y);
292292
}
293293

src/host/outputStream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ bool ConhostInternalGetSet::ResizeWindow(const til::CoordType sColumns, const ti
321321
api->GetConsoleScreenBufferInfoExImpl(screenInfo, csbiex);
322322

323323
const auto oldViewport = screenInfo.GetVirtualViewport();
324-
auto newViewport = Viewport::FromDimensions(oldViewport.Origin(), sColumns, sRows);
324+
auto newViewport = Viewport::FromDimensions(oldViewport.Origin(), { sColumns, sRows });
325325
// Always resize the width of the console
326326
csbiex.dwSize.X = gsl::narrow_cast<short>(sColumns);
327327
// Only set the screen buffer's height if it's currently less than

src/host/screenInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Viewport SCREEN_INFORMATION::GetTerminalBufferSize() const
163163
auto v = _textBuffer->GetSize();
164164
if (gci.IsTerminalScrolling() && v.Height() > _virtualBottom)
165165
{
166-
v = Viewport::FromDimensions({ 0, 0 }, v.Width(), _virtualBottom + 1);
166+
v = Viewport::FromDimensions({}, { v.Width(), _virtualBottom + 1 });
167167
}
168168
return v;
169169
}

0 commit comments

Comments
 (0)