diff --git a/src/host/selection.cpp b/src/host/selection.cpp index 5bc077e9aba..fd815e082ac 100644 --- a/src/host/selection.cpp +++ b/src/host/selection.cpp @@ -428,9 +428,9 @@ 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(); @@ -438,8 +438,8 @@ void Selection::ColorSelection(const til::inclusive_rect& srRect, const TextAttr 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; @@ -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(); diff --git a/src/host/selection.hpp b/src/host/selection.hpp index 8be598651a1..7ff876929ff 100644 --- a/src/host/selection.hpp +++ b/src/host/selection.hpp @@ -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 diff --git a/src/host/selectionInput.cpp b/src/host/selectionInput.cpp index 9a118ba08ce..d7f08d28bfb 100644 --- a/src/host/selectionInput.cpp +++ b/src/host/selectionInput.cpp @@ -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(); diff --git a/src/host/selectionState.cpp b/src/host/selectionState.cpp index 2504800bd93..c74e21dddd5 100644 --- a/src/host/selectionState.cpp +++ b/src/host/selectionState.cpp @@ -220,6 +220,23 @@ std::pair 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 };