From 019d66a4c626d9a8ee8a5e3a026eb680347598a0 Mon Sep 17 00:00:00 2001 From: Joakim Reinert Date: Wed, 27 Sep 2017 13:39:33 +0200 Subject: [PATCH 1/4] add adjustable delay for completion updates --- qutebrowser/completion/completer.py | 4 +++- qutebrowser/config/configdata.yml | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py index efd6b3490..23c77b59a 100644 --- a/qutebrowser/completion/completer.py +++ b/qutebrowser/completion/completer.py @@ -196,6 +196,8 @@ 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. """ if (self._cmd.cursorPosition() == self._last_cursor_pos and self._cmd.text() == self._last_text): @@ -203,7 +205,7 @@ class Completer(QObject): "changes.") else: log.completion.debug("Scheduling completion update.") - self._timer.start() + self._timer.start(config.val.completion.delay if self._last_text else 0) 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 f500a2f0f..71ab4c8b0 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -656,6 +656,13 @@ 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 + ## downloads downloads.location.directory: From 0226025308819df0381887e42ec14287d9e7c65b Mon Sep 17 00:00:00 2001 From: Joakim Reinert Date: Wed, 27 Sep 2017 13:41:06 +0200 Subject: [PATCH 2/4] add adjustable amount of chars required to update completions --- qutebrowser/completion/completer.py | 11 +++++++++-- qutebrowser/config/configdata.yml | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py index 23c77b59a..aa7f170a9 100644 --- a/qutebrowser/completion/completer.py +++ b/qutebrowser/completion/completer.py @@ -197,9 +197,16 @@ 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. + 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(' ') + if (0 < len(rest) < 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.") diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 71ab4c8b0..23349de29 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -663,6 +663,13 @@ completion.delay: 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: From 7c584e7b6c6a1514ecd28bc7962d63c74bab74e7 Mon Sep 17 00:00:00 2001 From: Joakim Reinert Date: Mon, 9 Oct 2017 16:23:45 +0200 Subject: [PATCH 3/4] add optional interval argument to start function of Timer stubs Fixes failing tests for completer --- tests/helpers/stubs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/helpers/stubs.py b/tests/helpers/stubs.py index 15d2ce8a0..d86d6c1d7 100644 --- a/tests/helpers/stubs.py +++ b/tests/helpers/stubs.py @@ -377,7 +377,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): @@ -396,7 +398,7 @@ class InstaTimer(QObject): timeout = pyqtSignal() - def start(self): + def start(self, interval=None): self.timeout.emit() def setSingleShot(self, yes): From efef588c30102edc9673a01442fe8198c7858576 Mon Sep 17 00:00:00 2001 From: Joakim Reinert Date: Thu, 12 Oct 2017 14:43:22 +0200 Subject: [PATCH 4/4] fix lints in completer --- qutebrowser/completion/completer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qutebrowser/completion/completer.py b/qutebrowser/completion/completer.py index aa7f170a9..eaf74f959 100644 --- a/qutebrowser/completion/completer.py +++ b/qutebrowser/completion/completer.py @@ -201,8 +201,9 @@ class Completer(QObject): updates if the text is shorter than completion.min_chars (unless we're hitting backspace in which case updates won't be ignored). """ - cmd, _sep, rest = self._cmd.text().partition(' ') - if (0 < len(rest) < config.val.completion.min_chars 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.") @@ -212,7 +213,8 @@ class Completer(QObject): "changes.") else: log.completion.debug("Scheduling completion update.") - self._timer.start(config.val.completion.delay if self._last_text else 0) + 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()