Fix color selection off-by-one error and dangling Y-beam (#18798)

(cherry picked from commit 0b4f9662c7f459857b08ef70c2cfb2b6e682c6c5)
Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgZYtao
Service-Version: 1.23
This commit is contained in:
Carlos Zamora 2025-04-14 21:17:57 -07:00 committed by Dustin L. Howett
parent cf3bbf53e6
commit 840f9623e5
4 changed files with 4 additions and 13 deletions

View File

@ -2061,14 +2061,6 @@ void TextBuffer::_ExpandTextRow(til::inclusive_rect& textRow) const
}
}
size_t TextBuffer::SpanLength(const til::point coordStart, const til::point coordEnd) const
{
const auto bufferSize = GetSize();
// The coords are inclusive, so to get the (inclusive) length we add 1.
const auto length = bufferSize.CompareInBounds(coordEnd, coordStart) + 1;
return gsl::narrow<size_t>(length);
}
// Routine Description:
// - Retrieves the plain text data between the specified coordinates.
// Arguments:

View File

@ -199,8 +199,6 @@ public:
std::wstring GetCustomIdFromId(uint16_t id) const;
void CopyHyperlinkMaps(const TextBuffer& OtherBuffer);
size_t SpanLength(const til::point coordStart, const til::point coordEnd) const;
std::wstring GetPlainText(til::point start, til::point end) const;
struct CopyRequest

View File

@ -2868,6 +2868,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// coloring other matches, then we need to make sure those get redrawn,
// too.
_renderer->TriggerRedrawAll();
_updateSelectionUI();
}
}
}

View File

@ -1571,10 +1571,10 @@ void Terminal::SerializeMainBuffer(const wchar_t* destination) const
void Terminal::ColorSelection(const TextAttribute& attr, winrt::Microsoft::Terminal::Core::MatchMode matchMode)
{
const auto colorSelection = [this](const til::point coordStart, const til::point coordEnd, const TextAttribute& attr) {
const auto colorSelection = [this](const til::point coordStartInclusive, const til::point coordEndExclusive, const TextAttribute& attr) {
auto& textBuffer = _activeBuffer();
const auto spanLength = textBuffer.SpanLength(coordStart, coordEnd);
textBuffer.Write(OutputCellIterator(attr, spanLength), coordStart);
const auto spanLength = textBuffer.GetSize().CompareInBounds(coordEndExclusive, coordStartInclusive, true);
textBuffer.Write(OutputCellIterator(attr, spanLength), coordStartInclusive);
};
for (const auto [start, end] : _GetSelectionSpans())