Add tests for selection persisting
- Remove unneeded override of qt home method
This commit is contained in:
parent
11b5958bc4
commit
9c73bf9e97
@ -105,13 +105,6 @@ class CommandLineEdit(QLineEdit):
|
|||||||
self._validator.prompt = text
|
self._validator.prompt = text
|
||||||
self._promptlen = len(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):
|
class _CommandValidator(QValidator):
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ class TestCommandLineEdit:
|
|||||||
assert cmd_edit.text() == ':hello'
|
assert cmd_edit.text() == ':hello'
|
||||||
assert cmd_edit.cursorPosition() == len(':hello')
|
assert cmd_edit.cursorPosition() == len(':hello')
|
||||||
|
|
||||||
cmd_edit.home(mark=True)
|
cmd_edit.home(True)
|
||||||
assert cmd_edit.cursorPosition() == len(':hello')
|
assert cmd_edit.cursorPosition() == len(':')
|
||||||
qtbot.keyClick(cmd_edit, Qt.Key_Delete)
|
qtbot.keyClick(cmd_edit, Qt.Key_Delete)
|
||||||
assert cmd_edit.text() == ':'
|
assert cmd_edit.text() == ':'
|
||||||
qtbot.keyClick(cmd_edit, Qt.Key_Backspace)
|
qtbot.keyClick(cmd_edit, Qt.Key_Backspace)
|
||||||
@ -74,6 +74,25 @@ class TestCommandLineEdit:
|
|||||||
qtbot.keyClicks(cmd_edit, '$hello')
|
qtbot.keyClicks(cmd_edit, '$hello')
|
||||||
assert cmd_edit.text() == ''
|
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):
|
class WrappedWidget(QWidget):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user