Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/host/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,18 @@ void Selection::ClearSelection(const bool fStartingNewSelection)
// - This does not validate whether there is a valid selection right now or not.
// It is assumed to already be in a proper selecting state and the given rectangle should be highlighted with the given color unconditionally.
// Arguments:
// - psrRect - Rectangular area to fill with color
// - psrRect - Rectangular area to fill with color (exclusive)
// - attr - The color attributes to apply
void Selection::ColorSelection(const til::inclusive_rect& srRect, const TextAttribute attr)
void Selection::ColorSelection(const til::rect& srRect, const TextAttribute attr)
{
auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();

// Read selection rectangle, assumed already clipped to buffer.
auto& screenInfo = gci.GetActiveOutputBuffer();

til::point coordTargetSize;
coordTargetSize.x = CalcWindowSizeX(srRect);
coordTargetSize.y = CalcWindowSizeY(srRect);
coordTargetSize.x = srRect.width();
coordTargetSize.y = srRect.height();

til::point coordTarget;
coordTarget.x = srRect.left;
Expand Down Expand Up @@ -475,9 +475,9 @@ void Selection::ColorSelection(const til::point coordSelectionStart, const til::
const auto& screenInfo = gci.GetActiveOutputBuffer();

const auto rectangles = screenInfo.GetTextBuffer().GetTextRects(coordSelectionStart, coordSelectionEnd, false, true);
for (const auto& rect : rectangles)
for (const auto& inclusiveRect : rectangles)
{
ColorSelection(rect, attr);
ColorSelection(til::rect{ inclusiveRect }, attr);
}
}
CATCH_LOG();
Expand Down
2 changes: 1 addition & 1 deletion src/host/selection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Selection

void ClearSelection();
void ClearSelection(const bool fStartingNewSelection);
void ColorSelection(const til::inclusive_rect& srRect, const TextAttribute attr);
void ColorSelection(const til::rect& srRect, const TextAttribute attr);
void ColorSelection(const til::point coordSelectionStart, const til::point coordSelectionEnd, const TextAttribute attr);

// delete these or we can accidentally get copies of the singleton
Expand Down
2 changes: 1 addition & 1 deletion src/host/selectionInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ bool Selection::_HandleColorSelection(const INPUT_KEY_INFO* const pInputKeyInfo)
for (auto&& sp : selection)
{
sp.iterate_rows(textBuffer.GetSize().Width(), [&](til::CoordType row, til::CoordType beg, til::CoordType end) {
ColorSelection({ beg, row, end, row }, selectionAttr);
ColorSelection({ beg, row, end, row + 1 }, selectionAttr);
});
}
ClearSelection();
Expand Down
17 changes: 17 additions & 0 deletions src/host/selectionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,23 @@ std::pair<til::point, til::point> Selection::GetSelectionAnchors() const noexcep
endSelectionAnchor.x = (_d->coordSelectionAnchor.x == _d->srSelectionRect.left) ? _d->srSelectionRect.right : _d->srSelectionRect.left;
endSelectionAnchor.y = (_d->coordSelectionAnchor.y == _d->srSelectionRect.top) ? _d->srSelectionRect.bottom : _d->srSelectionRect.top;

// GH #18106: Conhost and Terminal share most of the selection code.
// Both now store the selection data as a half-open range [start, end),
// where "end" is the bottom-right-most point.
// Conhost operates as an inclusive range, so we need to adjust the "end" endpoint by incrementing it by one.
const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
const auto& bufferSize = gci.GetActiveOutputBuffer().GetTextBuffer().GetSize();
if (IsLineSelection())
{
// General comparison for line selection.
bufferSize.IncrementInExclusiveBounds(startSelectionAnchor <= endSelectionAnchor ? endSelectionAnchor : startSelectionAnchor);
}
else
{
// Compare x-values when we're in block selection!
bufferSize.IncrementInExclusiveBounds(startSelectionAnchor.x <= endSelectionAnchor.x ? endSelectionAnchor : startSelectionAnchor);
}

if (startSelectionAnchor > endSelectionAnchor)
{
return { endSelectionAnchor, startSelectionAnchor };
Expand Down