diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py index 0840d6396..bc0e4991f 100644 --- a/qutebrowser/completion/completer.py +++ b/qutebrowser/completion/completer.py @@ -43,7 +43,6 @@ class Completer(QObject): Attributes: _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. _last_cursor_pos: The old cursor position so we avoid double completion updates. @@ -54,7 +53,6 @@ class Completer(QObject): def __init__(self, cmd, parent=None): super().__init__(parent) self._cmd = cmd - self._ignore_change = False self._timer = QTimer() self._timer.setSingleShot(True) self._timer.setInterval(0) @@ -178,13 +176,15 @@ class Completer(QObject): text = self._quote(text) model = self._model() if model.count() == 1 and config.val.completion.quick: - # If we only have one item, we want to apply it immediately - # and go on to the next part. - self._change_completed_part(text, before, after, immediate=True) + # If we only have one item, we want to apply it immediately and go + # on to the next part, unless we are quick-completing the part + # after maxsplit, so that we don't keep offering completions + # (see issue #1519) if maxsplit is not None and maxsplit < len(before): - # If we are quick-completing the part after maxsplit, don't - # keep offering completions (see issue #1519) - self._ignore_change = True + self._change_completed_part(text, before, after) + else: + self._change_completed_part(text, before, after, + immediate=True) else: self._change_completed_part(text, before, after) @@ -219,12 +219,6 @@ class Completer(QObject): @pyqtSlot() def _update_completion(self): """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() if self._cmd.prefix() != ':': diff --git a/tests/unit/completion/test_completer.py b/tests/unit/completion/test_completer.py index 8575cf02d..a32241621 100644 --- a/tests/unit/completion/test_completer.py +++ b/tests/unit/completion/test_completer.py @@ -274,7 +274,11 @@ def test_on_selection_changed(before, newtxt, after, completer_obj, check(True, 2, after_txt, after_pos) # 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 if after_pos > len(after_txt): after_txt += ' ' @@ -299,6 +303,11 @@ def test_quickcomplete_flicker(status_command_stub, completer_obj, config_stub.val.completion.quick = True _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.schedule_completion_update() assert not completion_widget_stub.set_model.called