Skip to content

Commit

Permalink
Fix UIA
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Oct 23, 2024
1 parent df89ad0 commit 9e9db42
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,14 @@ void TextBuffer::TriggerNewTextNotification(const std::wstring_view newText)
}
}

void TextBuffer::TriggerSelection()
{
if (_isActiveBuffer && _renderer)
{
_renderer->TriggerSelection();
}
}

// Method Description:
// - get delimiter class for buffer cell position
// - used for double click selection and uia word navigation
Expand Down
1 change: 1 addition & 0 deletions src/buffer/out/textBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class TextBuffer final
void TriggerScroll();
void TriggerScroll(const til::point delta);
void TriggerNewTextNotification(const std::wstring_view newText);
void TriggerSelection();

til::point GetWordStart(const til::point target, const std::wstring_view wordDelimiters, bool accessibilityMode = false, std::optional<til::point> limitOptional = std::nullopt) const;
til::point GetWordEnd(const til::point target, const std::wstring_view wordDelimiters, bool accessibilityMode = false, std::optional<til::point> limitOptional = std::nullopt) const;
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bufferSize.DecrementInBounds(inclusiveEnd);

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

void ControlCore::SelectCommand(const bool goUp)
Expand Down
3 changes: 0 additions & 3 deletions src/cascadia/TerminalCore/TerminalSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void Terminal::MultiClickSelection(const til::point viewportPos, SelectionExpans
selection->pivot = _ConvertToBufferCell(viewportPos, true);
selection->active = true;

// TODO CARLOS: validate
_multiClickSelectionMode = expansionMode;
SetSelectionEnd(viewportPos);

Expand All @@ -197,7 +196,6 @@ void Terminal::SetSelectionAnchor(const til::point viewportPos)
selection->pivot = _ConvertToBufferCell(viewportPos, true);
selection->active = true;

// TODO CARLOS: validate
_multiClickSelectionMode = SelectionExpansion::Char;
SetSelectionEnd(viewportPos);

Expand Down Expand Up @@ -916,7 +914,6 @@ Terminal::TextCopyData Terminal::RetrieveSelectedTextFromBuffer(const bool singl
// - the corresponding location on the buffer
til::point Terminal::_ConvertToBufferCell(const til::point viewportPos, bool allowRightExclusive) const
{
// TODO CARLOS: this is a dangerous change. Validate side-effects!
const auto yPos = _VisibleStartIndex() + viewportPos.y;
til::point bufferPos = { viewportPos.x, yPos };
const auto bufferSize = _activeBuffer().GetSize();
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/terminalrenderdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void Terminal::SelectNewRegion(const til::point coordStart, const til::point coo
const auto newCoordEnd = til::point{ coordEnd.x, coordEnd.y - newScrollOffset };
SetSelectionAnchor(newCoordStart);
SetSelectionEnd(newCoordEnd, SelectionExpansion::Char);
_activeBuffer().TriggerSelection();
}

const std::wstring_view Terminal::GetConsoleTitle() const noexcept
Expand Down
8 changes: 1 addition & 7 deletions src/types/TermControlUiaProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,8 @@ HRESULT TermControlUiaProvider::GetSelectionRange(_In_ IRawElementProviderSimple
RETURN_HR_IF_NULL(E_INVALIDARG, ppUtr);
*ppUtr = nullptr;

const auto start = _pData->GetSelectionAnchor();

// we need to make end exclusive
auto end = _pData->GetSelectionEnd();
_pData->GetTextBuffer().GetSize().IncrementInBounds(end, true);

TermControlUiaTextRange* result = nullptr;
RETURN_IF_FAILED(MakeAndInitialize<TermControlUiaTextRange>(&result, _pData, pProvider, start, end, _pData->IsBlockSelection(), wordDelimiters));
RETURN_IF_FAILED(MakeAndInitialize<TermControlUiaTextRange>(&result, _pData, pProvider, _pData->GetSelectionAnchor(), _pData->GetSelectionEnd(), _pData->IsBlockSelection(), wordDelimiters));
*ppUtr = result;
return S_OK;
}
Expand Down
8 changes: 2 additions & 6 deletions src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,9 @@ std::wstring UiaTextRangeBase::_getTextValue(til::CoordType maxLength) const

// TODO GH#5406: create a different UIA parent object for each TextBuffer
// nvaccess/nvda#11428: Ensure our endpoints are in bounds
THROW_HR_IF(E_FAIL, !bufferSize.IsInBounds(_start, true) || !bufferSize.IsInBounds(_end, true));
THROW_HR_IF(E_FAIL, !bufferSize.IsInExclusiveBounds(_start) || !bufferSize.IsInExclusiveBounds(_end));

// convert _end to be inclusive
auto inclusiveEnd = _end;
bufferSize.DecrementInBounds(inclusiveEnd, true);

const auto req = TextBuffer::CopyRequest{ buffer, _start, inclusiveEnd, _blockRange, true, false, false, true };
const auto req = TextBuffer::CopyRequest{ buffer, _start, _end, _blockRange, true, false, false, true };
auto plainText = buffer.GetPlainText(req);

if (plainText.size() > maxLengthAsSize)
Expand Down

0 comments on commit 9e9db42

Please sign in to comment.