summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2014-12-11 18:37:22 +0100
committerFlorian Bruhin <git@the-compiler.org>2014-12-11 18:37:22 +0100
commit8c4c465c914495e322de5d23b22648f98c734238 (patch)
tree08f21b4333417700cc597c9f9bd0b86e9a9220b0
parent4e6cedb1f71ac2a5b2c955f2783e0c45a64a543b (diff)
downloadqutebrowser-8c4c465c914495e322de5d23b22648f98c734238.tar.gz
qutebrowser-8c4c465c914495e322de5d23b22648f98c734238.zip
Fix completion update when the length is unchanged.
Fixes #312.
-rw-r--r--qutebrowser/utils/completer.py21
-rw-r--r--qutebrowser/widgets/statusbar/command.py6
2 files changed, 19 insertions, 8 deletions
diff --git a/qutebrowser/utils/completer.py b/qutebrowser/utils/completer.py
index c68b2a9a2..074aa5586 100644
--- a/qutebrowser/utils/completer.py
+++ b/qutebrowser/utils/completer.py
@@ -39,6 +39,9 @@ class Completer(QObject):
_win_id: The window ID this completer is in.
_timer: The timer used to trigger the completion update.
_cursor_part: The cursor part index for the next completion update.
+ _last_cursor_pos: The old cursor position so we avoid double completion
+ updates.
+ _last_text: The old command text so we avoid double completion updates.
"""
def __init__(self, cmd, win_id, parent=None):
@@ -62,6 +65,8 @@ class Completer(QObject):
self._timer.setInterval(0)
self._timer.timeout.connect(self.update_completion)
self._cursor_part = None
+ self._last_cursor_pos = None
+ self._last_text = None
def __repr__(self):
return utils.get_repr(self)
@@ -236,6 +241,7 @@ class Completer(QObject):
# and go on to the next part.
self.change_completed_part(data, immediate=True)
else:
+ log.completion.debug("Will ignore next completion update.")
self._ignore_change = True
self.change_completed_part(data)
@@ -246,8 +252,15 @@ class Completer(QObject):
For performance reasons we don't want to block here, instead we do this
in the background.
"""
- log.completion.debug("Scheduling completion update.")
- self._timer.start()
+ if (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()
+ self._last_cursor_pos = self._cmd.cursorPosition()
+ self._last_text = self._cmd.text()
@pyqtSlot()
def update_completion(self):
@@ -258,9 +271,11 @@ class Completer(QObject):
log.completion.debug(
"Updating completion - prefix {}, parts {}, cursor_part {}".format(
self._cmd.prefix(), parts, self._cursor_part))
+
if self._ignore_change:
+ log.completion.debug("Ignoring completion update because "
+ "ignore_change is True.")
self._ignore_change = False
- log.completion.debug("Ignoring completion update")
return
completion = objreg.get('completion', scope='window',
diff --git a/qutebrowser/widgets/statusbar/command.py b/qutebrowser/widgets/statusbar/command.py
index 55d6aefe9..9f4080ab8 100644
--- a/qutebrowser/widgets/statusbar/command.py
+++ b/qutebrowser/widgets/statusbar/command.py
@@ -68,6 +68,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
self.history.history = objreg.get('command-history').data
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Ignored)
self.cursorPositionChanged.connect(self.update_completion)
+ self.textChanged.connect(self.update_completion)
self.textChanged.connect(self.updateGeometry)
def prefix(self):
@@ -87,12 +88,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
Args:
text: The text to set as string.
"""
- old_text = self.text()
self.setText(text)
- if old_text != text and len(old_text) == len(text):
- # We want the completion to pop out here, but the cursor position
- # won't change, so we make sure we emit update_completion.
- self.update_completion.emit()
log.modes.debug("Setting command text, focusing {!r}".format(self))
self.setFocus()
self.show_cmd.emit()