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
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d91259
Add tests for other selection behavior in cursorManager.
jcsteh 21c18e0
cursorManager: Fix select all when the caret is in the middle or at t…
jcsteh 11b3136
cursorManager: Fix selecting forward, then selecting backward without…
jcsteh 28fe5b8
cursorManager: Fix unselecting to the beginning of the line. (#5746)
jcsteh 8b662c7
Add additional tests.
jcsteh 0eda1cb
Rename tests for consistency.
jcsteh File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ def test_selectNextChar(self): | |
self.assertEqual(cm.selectionOffsets, (0, 1)) # "a" selected | ||
|
||
def test_selectPrevChar(self): | ||
"""Same as test_selectNextChar, but with reversed direction. | ||
""" | ||
cm = CursorManager(text="abc", selection=(1, 1)) # Caret at "b" | ||
cm.script_selectCharacter_back(None) | ||
self.assertEqual(cm.selectionOffsets, (0, 1)) # "a" selected | ||
|
@@ -47,6 +49,32 @@ def test_unselectPrevChar(self): | |
cm.script_selectCharacter_back(None) # "a" unselected | ||
self.assertEqual(cm.selectionOffsets, (0, 0)) # Caret at "a", no selection | ||
|
||
def test_unselectNextChar(self): | ||
"""Depends on behavior tested by test_selectPrevChar. | ||
Same as test_unselectPrevChar, but with reversed directions. | ||
""" | ||
cm = CursorManager(text="abc", selection=(1, 1)) # Caret at "b" | ||
cm.script_selectCharacter_back(None) # "a" selected | ||
cm.script_selectCharacter_forward(None) # "a" unselected | ||
self.assertEqual(cm.selectionOffsets, (1, 1)) # Caret at "b", no selection | ||
|
||
def test_selectNextCharTwice(self): | ||
"""Depends on behavior tested in test_selectNextChar. | ||
""" | ||
cm = CursorManager(text="abc") # Caret at "a" | ||
cm.script_selectCharacter_forward(None) # "a" selected | ||
cm.script_selectCharacter_forward(None) # "b" selected | ||
self.assertEqual(cm.selectionOffsets, (0, 2)) # "ab" selected | ||
|
||
def test_selectPrevCharTwice(self): | ||
"""Depends on behavior tested in test_selectPrevChar. | ||
Same as test_selectNextCharTwice, but with reversed directions. | ||
""" | ||
cm = CursorManager(text="abc", selection=(2, 2)) # Caret at "c" | ||
cm.script_selectCharacter_back(None) # "b" selected | ||
cm.script_selectCharacter_back(None) # "a" selected | ||
self.assertEqual(cm.selectionOffsets, (0, 2)) # "ab" selected | ||
|
||
def test_selForwardThenUnselThenSelBackward(self): | ||
"""Test selecting forward, then unselecting and selecting backward. | ||
Depends on behavior tested by test_unselectPrevChar. | ||
|
@@ -57,6 +85,16 @@ def test_selForwardThenUnselThenSelBackward(self): | |
cm.script_selectCharacter_back(None) | ||
self.assertEqual(cm.selectionOffsets, (0, 1)) # "a" selected | ||
|
||
def test_selBackwardThenUnselThenSelForward(self): | ||
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 depends on |
||
"""Test selecting backward, then unselecting and selecting forward. | ||
Same as test_selForwardThenUnselThenSelBackward, but with reversed directions. | ||
""" | ||
cm = CursorManager(text="abc", selection=(1, 1)) # Caret at "b" | ||
cm.script_selectCharacter_back(None) # "a" selected | ||
cm.script_selectCharacter_forward(None) # "a" unselected, caret at "b" | ||
cm.script_selectCharacter_forward(None) | ||
self.assertEqual(cm.selectionOffsets, (1, 2)) # "b" selected | ||
|
||
def test_selectForwardThenSelBackward(self): | ||
"""Test selecting forward, then selecting backward without unselecting. | ||
Depends on behavior tested by test_selectNextChar. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't really understand the names "unselectPrevChar" and "unselectNextChar" somehow they seem the wrong way around? They might be clearer if called "selectPreviousUnsel" and "selectNextUnsel"
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.
In fact, the later tests use the term "forward" and "back" rather than "next" and "prev". It would be nice if we could be consistent here, I think forward and back make more sense since they are used in the name of the
script_
functions.