From 3eb15fc7637fdd587857d06ef2509fb2f8d913dd Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Thu, 3 Sep 2020 23:59:40 -0400 Subject: [PATCH 1/7] Keep degenerate UIA text ranges degenerate after movement. --- src/types/UiaTextRangeBase.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 1de46851558..dcdd552f5a9 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -579,6 +579,7 @@ IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, // We can abstract this movement by moving _start, but disallowing moving to the end of the buffer constexpr auto endpoint = TextPatternRangeEndpoint::TextPatternRangeEndpoint_Start; constexpr auto preventBufferEnd = true; + const auto wasDegenerate = IsDegenerate(); try { if (unit == TextUnit::TextUnit_Character) @@ -603,8 +604,17 @@ IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, // If we actually moved... if (*pRetVal != 0) { - // then just expand to get our _end - ExpandToEnclosingUnit(unit); + if (wasDegenerate) + { + // The range was degenerate before the move. + // To keep it that way, move _end to the new _start. + _end = _start; + } + else + { + // then just expand to get our _end + ExpandToEnclosingUnit(unit); + } } UiaTracing::TextRange::Move(unit, count, *pRetVal, *this); From c9f36610a0e0971628db1884146d7a520110f968 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Fri, 4 Sep 2020 13:15:59 -0400 Subject: [PATCH 2/7] Update src/types/UiaTextRangeBase.cpp Co-authored-by: Carlos Zamora --- src/types/UiaTextRangeBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index dcdd552f5a9..506b25cb104 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -606,7 +606,7 @@ IFACEMETHODIMP UiaTextRangeBase::Move(_In_ TextUnit unit, { if (wasDegenerate) { - // The range was degenerate before the move. + // GH#7342: The range was degenerate before the move. // To keep it that way, move _end to the new _start. _end = _start; } From f8e8af08b60d552d03084cba5d53a3588eb259f1 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Fri, 4 Sep 2020 13:18:39 -0400 Subject: [PATCH 3/7] Address review action. --- .../win32/ut_interactivity_win32/UiaTextRangeTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp index 4101aebfe09..38698ff2266 100644 --- a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp +++ b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp @@ -583,7 +583,7 @@ class UiaTextRangeTests { 5, {4 , 0 + 1}, - {5 , 0 + 1} + {4 , 0 + 1} } }, From 2d0427afd17dbb871311ef922ab2213a6bcccd53 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Fri, 4 Sep 2020 13:48:37 -0400 Subject: [PATCH 4/7] Add automated tests. --- .../UiaTextRangeTests.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp index 38698ff2266..55a44890ba8 100644 --- a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp +++ b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp @@ -695,6 +695,30 @@ class UiaTextRangeTests {0, bottomRow} } } + + MoveTest{ + L"can move to a new row when necessary when moving forward", + { lastColumnIndex, 0 }, + { lastColumnIndex, 0 }, + 5, + { + 5, + {lastColumnIndex , 0 + 5}, + {lastColumnIndex , 0 + 5} + } + }, + + MoveTest{ + L"can move to a new row when necessary when moving backward", + { 0, 0 + 1 }, + { lastColumnIndex, 0 + 1 }, + -5, + { + -5, + {lastColumnIndex - 5, 0}, + {lastColumnIndex - 5, 0} + } + } }; // clang-format on From b7973aaae7be71da9b3c74d2285621d94c648bcb Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Fri, 4 Sep 2020 14:03:58 -0400 Subject: [PATCH 5/7] Review actions. --- .../win32/ut_interactivity_win32/UiaTextRangeTests.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp index 55a44890ba8..c070c714cc9 100644 --- a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp +++ b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp @@ -710,13 +710,13 @@ class UiaTextRangeTests MoveTest{ L"can move to a new row when necessary when moving backward", - { 0, 0 + 1 }, - { lastColumnIndex, 0 + 1 }, + { 0, 7 }, + { 0, 7 }, -5, { -5, - {lastColumnIndex - 5, 0}, - {lastColumnIndex - 5, 0} + {0, 7 - 5}, + {0, 7 - 5} } } }; From a031ee383d55c03e862289106a043b69fe97da21 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Fri, 4 Sep 2020 14:28:29 -0400 Subject: [PATCH 6/7] I'm obviously not commatose enough... --- .../win32/ut_interactivity_win32/UiaTextRangeTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp index c070c714cc9..48a610f10fa 100644 --- a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp +++ b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp @@ -694,7 +694,7 @@ class UiaTextRangeTests {0, bottomRow}, {0, bottomRow} } - } + }, MoveTest{ L"can move to a new row when necessary when moving forward", From e01c57830ecb9a45be6d8786b0ed80c848cc5a75 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Fri, 4 Sep 2020 16:11:41 -0400 Subject: [PATCH 7/7] Update src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp Co-authored-by: Carlos Zamora --- .../win32/ut_interactivity_win32/UiaTextRangeTests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp index 48a610f10fa..414d3f52e68 100644 --- a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp +++ b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp @@ -703,8 +703,8 @@ class UiaTextRangeTests 5, { 5, - {lastColumnIndex , 0 + 5}, - {lastColumnIndex , 0 + 5} + {0, 0 + 5}, + {0, 0 + 5} } },