Merge pull request #3208 from 7lb/refactor/make_completer_less_stateful
[RDY] Make completer less stateful
This commit is contained in:
commit
d53a96d9f2
@ -43,7 +43,6 @@ class Completer(QObject):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
_cmd: The statusbar Command object this completer belongs to.
|
_cmd: The statusbar Command object this completer belongs to.
|
||||||
_ignore_change: Whether to ignore the next completion update.
|
|
||||||
_timer: The timer used to trigger the completion update.
|
_timer: The timer used to trigger the completion update.
|
||||||
_last_cursor_pos: The old cursor position so we avoid double completion
|
_last_cursor_pos: The old cursor position so we avoid double completion
|
||||||
updates.
|
updates.
|
||||||
@ -54,7 +53,6 @@ class Completer(QObject):
|
|||||||
def __init__(self, cmd, parent=None):
|
def __init__(self, cmd, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._cmd = cmd
|
self._cmd = cmd
|
||||||
self._ignore_change = False
|
|
||||||
self._timer = QTimer()
|
self._timer = QTimer()
|
||||||
self._timer.setSingleShot(True)
|
self._timer.setSingleShot(True)
|
||||||
self._timer.setInterval(0)
|
self._timer.setInterval(0)
|
||||||
@ -178,13 +176,15 @@ class Completer(QObject):
|
|||||||
text = self._quote(text)
|
text = self._quote(text)
|
||||||
model = self._model()
|
model = self._model()
|
||||||
if model.count() == 1 and config.val.completion.quick:
|
if model.count() == 1 and config.val.completion.quick:
|
||||||
# If we only have one item, we want to apply it immediately
|
# If we only have one item, we want to apply it immediately and go
|
||||||
# and go on to the next part.
|
# on to the next part, unless we are quick-completing the part
|
||||||
self._change_completed_part(text, before, after, immediate=True)
|
# after maxsplit, so that we don't keep offering completions
|
||||||
|
# (see issue #1519)
|
||||||
if maxsplit is not None and maxsplit < len(before):
|
if maxsplit is not None and maxsplit < len(before):
|
||||||
# If we are quick-completing the part after maxsplit, don't
|
self._change_completed_part(text, before, after)
|
||||||
# keep offering completions (see issue #1519)
|
else:
|
||||||
self._ignore_change = True
|
self._change_completed_part(text, before, after,
|
||||||
|
immediate=True)
|
||||||
else:
|
else:
|
||||||
self._change_completed_part(text, before, after)
|
self._change_completed_part(text, before, after)
|
||||||
|
|
||||||
@ -219,12 +219,6 @@ class Completer(QObject):
|
|||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _update_completion(self):
|
def _update_completion(self):
|
||||||
"""Check if completions are available and activate them."""
|
"""Check if completions are available and activate them."""
|
||||||
if self._ignore_change:
|
|
||||||
log.completion.debug("Ignoring completion update because "
|
|
||||||
"ignore_change is True.")
|
|
||||||
self._ignore_change = False
|
|
||||||
return
|
|
||||||
|
|
||||||
completion = self.parent()
|
completion = self.parent()
|
||||||
|
|
||||||
if self._cmd.prefix() != ':':
|
if self._cmd.prefix() != ':':
|
||||||
|
@ -274,7 +274,11 @@ def test_on_selection_changed(before, newtxt, after, completer_obj,
|
|||||||
check(True, 2, after_txt, after_pos)
|
check(True, 2, after_txt, after_pos)
|
||||||
|
|
||||||
# quick-completing a single item should move the cursor ahead by 1 and add
|
# quick-completing a single item should move the cursor ahead by 1 and add
|
||||||
# a trailing space if at the end of the cmd string
|
# a trailing space if at the end of the cmd string, unless the command has
|
||||||
|
# maxsplit < len(before) (such as :open in these tests)
|
||||||
|
if after_txt.startswith(':open'):
|
||||||
|
return
|
||||||
|
|
||||||
after_pos += 1
|
after_pos += 1
|
||||||
if after_pos > len(after_txt):
|
if after_pos > len(after_txt):
|
||||||
after_txt += ' '
|
after_txt += ' '
|
||||||
@ -299,6 +303,11 @@ def test_quickcomplete_flicker(status_command_stub, completer_obj,
|
|||||||
config_stub.val.completion.quick = True
|
config_stub.val.completion.quick = True
|
||||||
|
|
||||||
_set_cmd_prompt(status_command_stub, ':open |')
|
_set_cmd_prompt(status_command_stub, ':open |')
|
||||||
|
completer_obj.schedule_completion_update()
|
||||||
|
assert completion_widget_stub.set_model.called
|
||||||
|
completion_widget_stub.set_model.reset_mock()
|
||||||
|
|
||||||
|
# selecting a completion should not re-set the model
|
||||||
completer_obj.on_selection_changed('http://example.com')
|
completer_obj.on_selection_changed('http://example.com')
|
||||||
completer_obj.schedule_completion_update()
|
completer_obj.schedule_completion_update()
|
||||||
assert not completion_widget_stub.set_model.called
|
assert not completion_widget_stub.set_model.called
|
||||||
|
Loading…
Reference in New Issue
Block a user