diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py index efd6b3490..eaf74f959 100644 --- a/qutebrowser/completion/completer.py +++ b/qutebrowser/completion/completer.py @@ -196,14 +196,25 @@ class Completer(QObject): For performance reasons we don't want to block here, instead we do this in the background. + + We delay the update only if we've already input some text and ignore + updates if the text is shorter than completion.min_chars (unless we're + hitting backspace in which case updates won't be ignored). """ - if (self._cmd.cursorPosition() == self._last_cursor_pos and + _cmd, _sep, rest = self._cmd.text().partition(' ') + input_length = len(rest) + if (0 < input_length < config.val.completion.min_chars and + self._cmd.cursorPosition() > self._last_cursor_pos): + log.completion.debug("Ignoring update because the length of " + "the text is less than completion.min_chars.") + elif (self._cmd.cursorPosition() == self._last_cursor_pos and self._cmd.text() == self._last_text): log.completion.debug("Ignoring update because there were no " "changes.") else: log.completion.debug("Scheduling completion update.") - self._timer.start() + start_delay = config.val.completion.delay if self._last_text else 0 + self._timer.start(start_delay) self._last_cursor_pos = self._cmd.cursorPosition() self._last_text = self._cmd.text() diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index f4b484dbc..700dd4ddd 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -678,6 +678,20 @@ completion.web_history_max_items: 0: no history / -1: unlimited +completion.delay: + default: 0 + type: + name: Int + minval: 0 + desc: Delay in ms before updating completions after typing a character + +completion.min_chars: + default: 1 + type: + name: Int + minval: 1 + desc: Minimum amount of characters needed to update completions + ## downloads downloads.location.directory: diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index 1313649bc..c6f97b774 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -378,7 +378,9 @@ class FakeTimer(QObject): def isSingleShot(self): return self._singleshot - def start(self): + def start(self, interval=None): + if interval: + self._interval = interval self._started = True def stop(self): @@ -397,7 +399,7 @@ class InstaTimer(QObject): timeout = pyqtSignal() - def start(self): + def start(self, interval=None): self.timeout.emit() def setSingleShot(self, yes):