parent
7eba55459b
commit
6f3fde4450
@ -38,6 +38,10 @@ class Completer(QObject):
|
|||||||
_ignore_change: Whether to ignore the next completion update.
|
_ignore_change: Whether to ignore the next completion update.
|
||||||
models: dict of available completion models.
|
models: dict of available completion models.
|
||||||
_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.
|
||||||
|
_prefix: The prefix to be used for the next completion update.
|
||||||
|
_parts: The parts to be used for the next completion update.
|
||||||
|
_cursor_part: The cursor part index for the next completion update.
|
||||||
|
|
||||||
Signals:
|
Signals:
|
||||||
change_completed_part: Text which should be substituted for the word
|
change_completed_part: Text which should be substituted for the word
|
||||||
@ -62,6 +66,13 @@ class Completer(QObject):
|
|||||||
self._init_static_completions()
|
self._init_static_completions()
|
||||||
self._init_setting_completions()
|
self._init_setting_completions()
|
||||||
self.init_quickmark_completions()
|
self.init_quickmark_completions()
|
||||||
|
self._timer = QTimer()
|
||||||
|
self._timer.setSingleShot(True)
|
||||||
|
self._timer.setInterval(0)
|
||||||
|
self._timer.timeout.connect(self.update_completion)
|
||||||
|
self._prefix = None
|
||||||
|
self._parts = None
|
||||||
|
self._cursor_part = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self)
|
return utils.get_repr(self)
|
||||||
@ -215,17 +226,19 @@ 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.
|
||||||
"""
|
"""
|
||||||
QTimer.singleShot(0, functools.partial(
|
self._timer.start()
|
||||||
self._on_update_completion, prefix, parts, cursor_part))
|
self._prefix = prefix
|
||||||
|
self._parts = parts
|
||||||
|
self._cursor_part = cursor_part
|
||||||
|
|
||||||
@pyqtSlot(str, list, int)
|
@pyqtSlot()
|
||||||
def _on_update_completion(self, prefix, parts, cursor_part):
|
def update_completion(self):
|
||||||
"""Check if completions are available and activate them.
|
"""Check if completions are available and activate them."""
|
||||||
|
|
||||||
|
assert self._prefix is not None
|
||||||
|
assert self._parts is not None
|
||||||
|
assert self._cursor_part is not None
|
||||||
|
|
||||||
Args:
|
|
||||||
text: The new text
|
|
||||||
cursor_part: The part the cursor is currently over.
|
|
||||||
"""
|
|
||||||
if self._ignore_change:
|
if self._ignore_change:
|
||||||
self._ignore_change = False
|
self._ignore_change = False
|
||||||
log.completion.debug("Ignoring completion update")
|
log.completion.debug("Ignoring completion update")
|
||||||
@ -234,7 +247,7 @@ class Completer(QObject):
|
|||||||
completion = objreg.get('completion', scope='window',
|
completion = objreg.get('completion', scope='window',
|
||||||
window=self._win_id)
|
window=self._win_id)
|
||||||
|
|
||||||
if prefix != ':':
|
if self._prefix != ':':
|
||||||
# This is a search or gibberish, so we don't need to complete
|
# This is a search or gibberish, so we don't need to complete
|
||||||
# anything (yet)
|
# anything (yet)
|
||||||
# FIXME complete searchs
|
# FIXME complete searchs
|
||||||
@ -242,7 +255,7 @@ class Completer(QObject):
|
|||||||
completion.hide()
|
completion.hide()
|
||||||
return
|
return
|
||||||
|
|
||||||
model = self._get_new_completion(parts, cursor_part)
|
model = self._get_new_completion(self._parts, self._cursor_part)
|
||||||
|
|
||||||
if model != self._model():
|
if model != self._model():
|
||||||
if model is None:
|
if model is None:
|
||||||
@ -251,15 +264,16 @@ class Completer(QObject):
|
|||||||
completion.set_model(model)
|
completion.set_model(model)
|
||||||
|
|
||||||
if model is None:
|
if model is None:
|
||||||
log.completion.debug("No completion model for {}.".format(parts))
|
log.completion.debug("No completion model for {}.".format(
|
||||||
|
self._parts))
|
||||||
return
|
return
|
||||||
|
|
||||||
pattern = parts[cursor_part] if parts else ''
|
pattern = self._parts[self._cursor_part] if self._parts else ''
|
||||||
self._model().set_pattern(pattern)
|
self._model().set_pattern(pattern)
|
||||||
|
|
||||||
log.completion.debug(
|
log.completion.debug(
|
||||||
"New completion for {}: {}, with pattern '{}'".format(
|
"New completion for {}: {}, with pattern '{}'".format(
|
||||||
parts, model.srcmodel.__class__.__name__, pattern))
|
self._parts, model.srcmodel.__class__.__name__, pattern))
|
||||||
|
|
||||||
if self._model().count() == 0:
|
if self._model().count() == 0:
|
||||||
completion.hide()
|
completion.hide()
|
||||||
|
Loading…
Reference in New Issue
Block a user