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

Fix cursorManager selection bugs #7131

Merged
merged 6 commits into from May 8, 2017

Conversation

Projects
None yet
4 participants
@jcsteh
Contributor

jcsteh commented May 3, 2017

  • In browse mode, pressing shift+home after selecting forward now unselects to the beginning of the line as expected. (#5746)
  • In browse mode, select all (control+a) no longer fails to select all text if the caret is not at the start of the text. (#6909)
  • cursorManager: Fix selecting forward, then selecting backward without unselecting, then unselecting forward, and vice versa. This one is hard to explain; see the unit tests for details.

This should be merged normally, not squashed.

Fixes #5746. Fixes #6909.

@jcsteh jcsteh added the p1 label May 3, 2017

@jcsteh jcsteh requested a review from feerrenrut May 3, 2017

cm.script_selectWord_forward(None) # "b" unselected, "c" selected
cm.script_selectCharacter_back(None) # "c" unselected
self.assertEqual(cm.selectionOffsets, (2, 2)) # Caret at "c", no selection

This comment has been minimized.

@feerrenrut

feerrenrut May 3, 2017

Contributor

There is no coverage for selectBackwardThenUnselThenSelForward but there is for selectForwardThenUnselThenSelBackward?

Can these tests be broken down? Is there state that can only be achieved by using the script methods? For instance, instead of testing as in test_selectBackwardThenSelForwardThenUnsel, instead have three tests (using a naming scheme of given_do_expect:

test_caretAtC_SelectCharBack_bSelected

cm = CursorManager(text="abc", selection=(2, 2)) # Caret at "c"
cm.script_selectCharacter_back(None) # "b" selected
self.assertEqual(cm.selectionOffsets, (1, 2)) # 'b' selected

test_bSelected_selectWordForward_cSelected

cm = CursorManager(text="abc", selection=(1, 2)) #'b' selected
cm.script_selectWord_forward(None) # "b" unselected, "c" selected
self.assertEqual(cm.selectionOffsets, (2, 3)) # 'c' selected

test_cSelected_selectCharacterBack_NoSelection

cm = CursorManager(text="abc", selection=(2, 3)) #'c' selected
cm.script_selectCharacter_back(None) # "c" unselected
self.assertEqual(cm.selectionOffsets, (2, 2)) # Caret at "c", no selection

Perhaps there is a reason we cant do this, like some state on CursorManager that we can not set through the constructor. But if we can I think this makes it easier to verify good test coverage.

@feerrenrut

feerrenrut May 3, 2017

Contributor

There is no coverage for selectBackwardThenUnselThenSelForward but there is for selectForwardThenUnselThenSelBackward?

Can these tests be broken down? Is there state that can only be achieved by using the script methods? For instance, instead of testing as in test_selectBackwardThenSelForwardThenUnsel, instead have three tests (using a naming scheme of given_do_expect:

test_caretAtC_SelectCharBack_bSelected

cm = CursorManager(text="abc", selection=(2, 2)) # Caret at "c"
cm.script_selectCharacter_back(None) # "b" selected
self.assertEqual(cm.selectionOffsets, (1, 2)) # 'b' selected

test_bSelected_selectWordForward_cSelected

cm = CursorManager(text="abc", selection=(1, 2)) #'b' selected
cm.script_selectWord_forward(None) # "b" unselected, "c" selected
self.assertEqual(cm.selectionOffsets, (2, 3)) # 'c' selected

test_cSelected_selectCharacterBack_NoSelection

cm = CursorManager(text="abc", selection=(2, 3)) #'c' selected
cm.script_selectCharacter_back(None) # "c" unselected
self.assertEqual(cm.selectionOffsets, (2, 2)) # Caret at "c", no selection

Perhaps there is a reason we cant do this, like some state on CursorManager that we can not set through the constructor. But if we can I think this makes it easier to verify good test coverage.

This comment has been minimized.

@jcsteh

jcsteh May 3, 2017

Contributor

There is no coverage for selectBackwardThenUnselThenSelForward but there is for selectForwardThenUnselThenSelBackward ?

This was an oversight when I wrote the original batch of tests. I shall fix.

Can these tests be broken down? Is there state that can only be achieved by using the script methods?

Yes; there is state here that is only set by the methods. I could set it manually for testing; it's just a boolean, though it's not something that should normally be tweaked by a caller. However, a big part of what we're testing here is that the state gets set correctly throughout these various movements. I'm concerned we might miss something if we initialise state directly, especially since it's already somewhat hard to grasp how one might get into various states.

@jcsteh

jcsteh May 3, 2017

Contributor

There is no coverage for selectBackwardThenUnselThenSelForward but there is for selectForwardThenUnselThenSelBackward ?

This was an oversight when I wrote the original batch of tests. I shall fix.

Can these tests be broken down? Is there state that can only be achieved by using the script methods?

Yes; there is state here that is only set by the methods. I could set it manually for testing; it's just a boolean, though it's not something that should normally be tweaked by a caller. However, a big part of what we're testing here is that the state gets set correctly throughout these various movements. I'm concerned we might miss something if we initialise state directly, especially since it's already somewhat hard to grasp how one might get into various states.

@@ -79,3 +154,9 @@ def _selectAllTest(self, caret):
def test_selectAllFromStart(self):
self._selectAllTest(0) # Caret at "a"
def test_selectAllFromMiddle(self):
self._selectAllTest(1) # Caret at "b"

This comment has been minimized.

@feerrenrut

feerrenrut May 3, 2017

Contributor

What kind of error message do you get when this fails?

@feerrenrut

feerrenrut May 3, 2017

Contributor

What kind of error message do you get when this fails?

This comment has been minimized.

@jcsteh

jcsteh May 3, 2017

Contributor

Reverting the fix, we get this:

FAIL: test_selectAllFromMiddle (tests.unit.test_cursorManager.TestSelectAll)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\jamie\src\nvda\tests\unit\test_cursorManager.py", line 169, in test_selectAllFromMiddle
    self._selectAllTest(1) # Caret at "b"
  File "C:\Users\jamie\src\nvda\tests\unit\test_cursorManager.py", line 163, in _selectAllTest
    self.assertEqual(cm.selectionOffsets, (0, 3)) # "abc" selected
AssertionError: Tuples differ: (0, 1) != (0, 3)
@jcsteh

jcsteh May 3, 2017

Contributor

Reverting the fix, we get this:

FAIL: test_selectAllFromMiddle (tests.unit.test_cursorManager.TestSelectAll)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\jamie\src\nvda\tests\unit\test_cursorManager.py", line 169, in test_selectAllFromMiddle
    self._selectAllTest(1) # Caret at "b"
  File "C:\Users\jamie\src\nvda\tests\unit\test_cursorManager.py", line 163, in _selectAllTest
    self.assertEqual(cm.selectionOffsets, (0, 3)) # "abc" selected
AssertionError: Tuples differ: (0, 1) != (0, 3)
Show outdated Hide outdated tests/unit/test_cursorManager.py
Show outdated Hide outdated tests/unit/test_cursorManager.py
@jcsteh

This comment has been minimized.

Show comment
Hide comment
@jcsteh

jcsteh May 8, 2017

Contributor

@michaelDCurran, @feerrenrut and I all agreed this should be merged into master before the translation freeze despite it not being fully incubated, as it it is a p1 fix which needs to be included in the release.

Contributor

jcsteh commented May 8, 2017

@michaelDCurran, @feerrenrut and I all agreed this should be merged into master before the translation freeze despite it not being fully incubated, as it it is a p1 fix which needs to be included in the release.

@Adriani90

This comment has been minimized.

Show comment
Hide comment
@Adriani90

Adriani90 Jul 12, 2018

Why has this pull request not been merged in 2017.2?

Adriani90 commented Jul 12, 2018

Why has this pull request not been merged in 2017.2?

@jcsteh

This comment has been minimized.

Show comment
Hide comment
@jcsteh

jcsteh Jul 13, 2018

Contributor

@Adriani90 commented on Jul 13, 2018, 5:04 AM GMT+10:

Why has this pull request not been merged in 2017.2?

It was. The PR is marked as merged, has its milestone set to 2017.2 and has entries in the What's New for the issues it fixes.

Contributor

jcsteh commented Jul 13, 2018

@Adriani90 commented on Jul 13, 2018, 5:04 AM GMT+10:

Why has this pull request not been merged in 2017.2?

It was. The PR is marked as merged, has its milestone set to 2017.2 and has entries in the What's New for the issues it fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment