Add tests for selection persisting

- Remove unneeded override of qt home method
This commit is contained in:
Jay Kamat 2018-10-27 16:12:15 -07:00
parent 11b5958bc4
commit 9c73bf9e97
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5
2 changed files with 21 additions and 9 deletions

View File

@ -105,13 +105,6 @@ class CommandLineEdit(QLineEdit):
self._validator.prompt = text
self._promptlen = len(text)
def home(self, mark):
"""Override home so it works properly with our cursor restriction."""
oldpos = self.cursorPosition()
self.setCursorPosition(self._promptlen)
if mark:
self.setSelection(self._promptlen, oldpos - self._promptlen)
class _CommandValidator(QValidator):

View File

@ -59,8 +59,8 @@ class TestCommandLineEdit:
assert cmd_edit.text() == ':hello'
assert cmd_edit.cursorPosition() == len(':hello')
cmd_edit.home(mark=True)
assert cmd_edit.cursorPosition() == len(':hello')
cmd_edit.home(True)
assert cmd_edit.cursorPosition() == len(':')
qtbot.keyClick(cmd_edit, Qt.Key_Delete)
assert cmd_edit.text() == ':'
qtbot.keyClick(cmd_edit, Qt.Key_Backspace)
@ -74,6 +74,25 @@ class TestCommandLineEdit:
qtbot.keyClicks(cmd_edit, '$hello')
assert cmd_edit.text() == ''
def test_selection_home(self, qtbot, cmd_edit):
"""Test selection persisting when pressing home."""
qtbot.keyClicks(cmd_edit, ':hello')
assert cmd_edit.text() == ':hello'
assert cmd_edit.cursorPosition() == len(':hello')
cmd_edit.home(True)
assert cmd_edit.cursorPosition() == len(':')
assert cmd_edit.selectionStart() == len(':')
def test_selection_backspace(self, qtbot, cmd_edit):
"""Test selection persisting when backspacing to the first char."""
qtbot.keyClicks(cmd_edit, ':hello')
assert cmd_edit.text() == ':hello'
assert cmd_edit.cursorPosition() == len(':hello')
for _ in range(len(':hello')):
qtbot.keyClick(cmd_edit, Qt.Key_Left, modifier=Qt.ShiftModifier)
assert cmd_edit.cursorPosition() == len(':')
assert cmd_edit.selectionStart() == len(':')
class WrappedWidget(QWidget):