-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly handle and test a11y movement at end of buffer #7792
Changes from 2 commits
2470d33
5e87c50
e13ea08
520ad92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1136,57 +1136,82 @@ class UiaTextRangeTests | |
// the UTR should refuse to move past the end. | ||
|
||
const auto bufferSize{ _pTextBuffer->GetSize() }; | ||
const til::point endInclusive = { bufferSize.RightInclusive(), bufferSize.BottomInclusive() }; | ||
const auto endExclusive{ bufferSize.EndExclusive() }; | ||
const COORD origin{ bufferSize.Origin() }; | ||
const COORD lastLineStart{ bufferSize.Left(), bufferSize.BottomInclusive() }; | ||
const COORD secondToLastCharacterPos{ bufferSize.RightInclusive() - 1, bufferSize.BottomInclusive() }; | ||
const COORD endInclusive{ bufferSize.RightInclusive(), bufferSize.BottomInclusive() }; | ||
const COORD endExclusive{ bufferSize.EndExclusive() }; | ||
|
||
// Iterate over each TextUnit. If the we don't support | ||
// Iterate over each TextUnit. If we don't support | ||
// the given TextUnit, we're supposed to fallback | ||
// to the last one that was defined anyways. | ||
BEGIN_TEST_METHOD_PROPERTIES() | ||
TEST_METHOD_PROPERTY(L"Data:textUnit", L"{0, 1, 2, 3, 4, 5, 6}") | ||
TEST_METHOD_PROPERTY(L"Data:degenerate", L"{false, true}") | ||
END_TEST_METHOD_PROPERTIES(); | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
int unit; | ||
bool degenerate; | ||
VERIFY_SUCCEEDED(TestData::TryGetValue(L"textUnit", unit), L"Get TextUnit variant"); | ||
VERIFY_SUCCEEDED(TestData::TryGetValue(L"degenerate", degenerate), L"Get degenerate variant"); | ||
TextUnit textUnit{ static_cast<TextUnit>(unit) }; | ||
|
||
Microsoft::WRL::ComPtr<UiaTextRange> utr; | ||
int moveAmt; | ||
for (int unit = TextUnit::TextUnit_Character; unit != TextUnit::TextUnit_Document; ++unit) | ||
{ | ||
Log::Comment(NoThrowString().Format(L"Forward by %s", toString(static_cast<TextUnit>(unit)))); | ||
Log::Comment(NoThrowString().Format(L"Forward by %s", toString(textUnit))); | ||
|
||
// Create a degenerate UTR at EndExclusive | ||
// Create an UTR at EndExclusive | ||
if (degenerate) | ||
{ | ||
THROW_IF_FAILED(Microsoft::WRL::MakeAndInitialize<UiaTextRange>(&utr, _pUiaData, &_dummyProvider, endExclusive, endExclusive)); | ||
} | ||
else | ||
{ | ||
THROW_IF_FAILED(Microsoft::WRL::MakeAndInitialize<UiaTextRange>(&utr, _pUiaData, &_dummyProvider, endInclusive, endExclusive)); | ||
THROW_IF_FAILED(utr->Move(static_cast<TextUnit>(unit), 1, &moveAmt)); | ||
|
||
VERIFY_ARE_EQUAL(endExclusive, utr->_end); | ||
VERIFY_ARE_EQUAL(0, moveAmt); | ||
} | ||
THROW_IF_FAILED(utr->Move(textUnit, 1, &moveAmt)); | ||
|
||
VERIFY_ARE_EQUAL(endExclusive, utr->_end); | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
VERIFY_ARE_EQUAL(0, moveAmt); | ||
|
||
// Verify that moving backwards still works properly | ||
|
||
// write "temp" at (2,2) | ||
const COORD writeTarget{ 2, 2 }; | ||
_pTextBuffer->Write({ L"temp" }, writeTarget); | ||
for (int unit = TextUnit::TextUnit_Character; unit != TextUnit::TextUnit_Document; ++unit) | ||
{ | ||
COORD expectedEnd; | ||
switch (static_cast<TextUnit>(unit)) | ||
{ | ||
case TextUnit::TextUnit_Character: | ||
expectedEnd = endInclusive; | ||
break; | ||
case TextUnit::TextUnit_Word: | ||
expectedEnd = writeTarget; | ||
break; | ||
case TextUnit::TextUnit_Line: | ||
expectedEnd = endExclusive; | ||
break; | ||
case TextUnit::TextUnit_Document: | ||
expectedEnd = bufferSize.Origin(); | ||
break; | ||
default: | ||
continue; | ||
} | ||
|
||
Log::Comment(NoThrowString().Format(L"Backwards by %s", toString(static_cast<TextUnit>(unit)))); | ||
//if (textUnit == TextUnit::TextUnit_Character && !degenerate) | ||
// DebugBreak(); | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Create a degenerate UTR at EndExclusive | ||
THROW_IF_FAILED(Microsoft::WRL::MakeAndInitialize<UiaTextRange>(&utr, _pUiaData, &_dummyProvider, endInclusive, endExclusive)); | ||
THROW_IF_FAILED(utr->Move(static_cast<TextUnit>(unit), -1, &moveAmt)); | ||
Log::Comment(NoThrowString().Format(L"Backwards by %s", toString(textUnit))); | ||
THROW_IF_FAILED(utr->Move(textUnit, -1, &moveAmt)); | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
VERIFY_ARE_EQUAL(expectedEnd, utr->_end); | ||
// NOTE: If the range is degenerate, _start == _end before AND after the move. | ||
if (textUnit <= TextUnit::TextUnit_Character) | ||
{ | ||
// Special case: _end will always be endInclusive, because... | ||
// - degenerate --> it moves with _start to stay degenerate | ||
// - !degenerate --> it excludes the last char, to select the second to last char | ||
VERIFY_ARE_EQUAL(degenerate ? endInclusive : secondToLastCharacterPos, utr->_start); | ||
VERIFY_ARE_EQUAL(endInclusive, utr->_end); | ||
VERIFY_ARE_EQUAL(-1, moveAmt); | ||
} | ||
else if (textUnit <= TextUnit::TextUnit_Word) | ||
{ | ||
VERIFY_ARE_EQUAL(origin, utr->_start); | ||
VERIFY_ARE_EQUAL(degenerate ? origin : writeTarget, utr->_end); | ||
VERIFY_ARE_EQUAL(-1, moveAmt); | ||
} | ||
else if (textUnit <= TextUnit::TextUnit_Line) | ||
{ | ||
VERIFY_ARE_EQUAL(lastLineStart, utr->_start); | ||
VERIFY_ARE_EQUAL(degenerate ? lastLineStart : endExclusive, utr->_end); | ||
VERIFY_ARE_EQUAL(-1, moveAmt); | ||
} | ||
else // textUnit <= TextUnit::TextUnit_Document: | ||
{ | ||
VERIFY_ARE_EQUAL(origin, utr->_start); | ||
VERIFY_ARE_EQUAL(degenerate ? origin : endExclusive, utr->_end); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i know it might be a chore, but having @codeofdusk review this test case for sanity would be helpful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (a chore for him, not a chore for you. since this is a bunch of dense WEX C++) |
||
VERIFY_ARE_EQUAL(-1, moveAmt); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -953,7 +953,7 @@ void UiaTextRangeBase::_moveEndpointByUnitCharacter(_In_ const int moveCount, | |
} | ||
break; | ||
case MovementDirection::Backward: | ||
success = buffer.MoveToPreviousGlyph(target, allowBottomExclusive); | ||
success = buffer.MoveToPreviousGlyph(target); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is because it is safe to move backwards off the exclusive end, and you're checking before loading the glyph data that it is a valid position? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. It's safe to move backwards off the exclusive end. So let's not bother passing in |
||
if (success) | ||
{ | ||
(*pAmountMoved)--; | ||
|
@@ -1123,7 +1123,7 @@ void UiaTextRangeBase::_moveEndpointByUnitLine(_In_ const int moveCount, | |
} | ||
|
||
// NOTE: Automatically detects if we are trying to move past origin | ||
success = bufferSize.DecrementInBounds(nextPos, allowBottomExclusive); | ||
success = bufferSize.DecrementInBounds(nextPos, true); | ||
|
||
if (success) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the fix for the crash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. In general, I thought it was only possible for
_end
to be atEndExclusive()
, soallowBottomExclusive
is used to track if we are working with_end
. That definitely wasn't the case because you can end up with_start
atEndExclusive()
by doing the repro steps.So this check for
EndExclusive()
is basically thrown around everywhere to ensure we don't crash on anIncrementInBounds
orDecrementInBounds
check (which checks if the COORD is in the buffer, andEndExclusive
isn't)