parent
4e6cedb1f7
commit
8c4c465c91
@ -39,6 +39,9 @@ class Completer(QObject):
|
|||||||
_win_id: The window ID this completer is in.
|
_win_id: The window ID this completer is in.
|
||||||
_timer: The timer used to trigger the completion update.
|
_timer: The timer used to trigger the completion update.
|
||||||
_cursor_part: The cursor part index for the next 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):
|
def __init__(self, cmd, win_id, parent=None):
|
||||||
@ -62,6 +65,8 @@ class Completer(QObject):
|
|||||||
self._timer.setInterval(0)
|
self._timer.setInterval(0)
|
||||||
self._timer.timeout.connect(self.update_completion)
|
self._timer.timeout.connect(self.update_completion)
|
||||||
self._cursor_part = None
|
self._cursor_part = None
|
||||||
|
self._last_cursor_pos = None
|
||||||
|
self._last_text = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self)
|
return utils.get_repr(self)
|
||||||
@ -236,6 +241,7 @@ class Completer(QObject):
|
|||||||
# and go on to the next part.
|
# and go on to the next part.
|
||||||
self.change_completed_part(data, immediate=True)
|
self.change_completed_part(data, immediate=True)
|
||||||
else:
|
else:
|
||||||
|
log.completion.debug("Will ignore next completion update.")
|
||||||
self._ignore_change = True
|
self._ignore_change = True
|
||||||
self.change_completed_part(data)
|
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
|
For performance reasons we don't want to block here, instead we do this
|
||||||
in the background.
|
in the background.
|
||||||
"""
|
"""
|
||||||
log.completion.debug("Scheduling completion update.")
|
if (self._cmd.cursorPosition() == self._last_cursor_pos and
|
||||||
self._timer.start()
|
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()
|
@pyqtSlot()
|
||||||
def update_completion(self):
|
def update_completion(self):
|
||||||
@ -258,9 +271,11 @@ class Completer(QObject):
|
|||||||
log.completion.debug(
|
log.completion.debug(
|
||||||
"Updating completion - prefix {}, parts {}, cursor_part {}".format(
|
"Updating completion - prefix {}, parts {}, cursor_part {}".format(
|
||||||
self._cmd.prefix(), parts, self._cursor_part))
|
self._cmd.prefix(), parts, self._cursor_part))
|
||||||
|
|
||||||
if self._ignore_change:
|
if self._ignore_change:
|
||||||
|
log.completion.debug("Ignoring completion update because "
|
||||||
|
"ignore_change is True.")
|
||||||
self._ignore_change = False
|
self._ignore_change = False
|
||||||
log.completion.debug("Ignoring completion update")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
completion = objreg.get('completion', scope='window',
|
completion = objreg.get('completion', scope='window',
|
||||||
|
@ -68,6 +68,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
|||||||
self.history.history = objreg.get('command-history').data
|
self.history.history = objreg.get('command-history').data
|
||||||
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Ignored)
|
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Ignored)
|
||||||
self.cursorPositionChanged.connect(self.update_completion)
|
self.cursorPositionChanged.connect(self.update_completion)
|
||||||
|
self.textChanged.connect(self.update_completion)
|
||||||
self.textChanged.connect(self.updateGeometry)
|
self.textChanged.connect(self.updateGeometry)
|
||||||
|
|
||||||
def prefix(self):
|
def prefix(self):
|
||||||
@ -87,12 +88,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
|||||||
Args:
|
Args:
|
||||||
text: The text to set as string.
|
text: The text to set as string.
|
||||||
"""
|
"""
|
||||||
old_text = self.text()
|
|
||||||
self.setText(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))
|
log.modes.debug("Setting command text, focusing {!r}".format(self))
|
||||||
self.setFocus()
|
self.setFocus()
|
||||||
self.show_cmd.emit()
|
self.show_cmd.emit()
|
||||||
|
Loading…
Reference in New Issue
Block a user