Don't instantiate completion models nedlessly.
For real this time. A mistake on the last commit like this meant models were still spuriously instantiated. Now that the completion model is reused, the layoutChanged signal needs to be forwarded through, otherwise the view will not update.
This commit is contained in:
parent
42243d3d97
commit
565ba23f8c
@ -224,20 +224,19 @@ class Completer(QObject):
|
||||
if func is None:
|
||||
log.completion.debug('Clearing completion')
|
||||
completion.set_model(None)
|
||||
elif func != self._last_completion_func:
|
||||
self._last_completion_func = None
|
||||
return
|
||||
|
||||
if func != self._last_completion_func:
|
||||
self._last_completion_func = func
|
||||
args = (x for x in before_cursor[1:] if not x.startswith('-'))
|
||||
with debug.log_time(log.completion,
|
||||
'Instantiate {} completion'.format(func.__name__)):
|
||||
'Starting {} completion'.format(func.__name__)):
|
||||
model = func(*args)
|
||||
with debug.log_time(log.completion, 'Set completion model'):
|
||||
completion.set_model(model)
|
||||
completion.set_pattern(pattern)
|
||||
else:
|
||||
log.completion.debug('Setting pattern {}'.format(pattern))
|
||||
completion.set_pattern(pattern)
|
||||
|
||||
self._last_completion_func = None
|
||||
completion.set_pattern(pattern)
|
||||
|
||||
def _change_completed_part(self, newtext, before, after, immediate=False):
|
||||
"""Change the part we're currently completing in the commandline.
|
||||
|
@ -283,8 +283,6 @@ class CompletionView(QTreeView):
|
||||
self._column_widths = model.column_widths
|
||||
self._active = True
|
||||
|
||||
self.set_pattern('')
|
||||
|
||||
if (config.get('completion', 'show') == 'always' and
|
||||
model.count() > 0):
|
||||
self.show()
|
||||
|
@ -63,6 +63,7 @@ class CompletionModel(QAbstractItemModel):
|
||||
def add_category(self, cat):
|
||||
"""Add a completion category to the model."""
|
||||
self._categories.append(cat)
|
||||
cat.layoutChanged.connect(self.layoutChanged)
|
||||
|
||||
def data(self, index, role=Qt.DisplayRole):
|
||||
"""Return the item data for index.
|
||||
|
@ -56,7 +56,7 @@ def test_first_last_item(counts):
|
||||
def test_count(counts):
|
||||
model = completionmodel.CompletionModel()
|
||||
for c in counts:
|
||||
cat = mock.Mock(spec=['rowCount'])
|
||||
cat = mock.Mock(spec=['rowCount', 'layoutChanged'])
|
||||
cat.rowCount = mock.Mock(return_value=c)
|
||||
model.add_category(cat)
|
||||
assert model.count() == sum(counts)
|
||||
@ -66,7 +66,7 @@ def test_count(counts):
|
||||
def test_set_pattern(pat):
|
||||
"""Validate the filtering and sorting results of set_pattern."""
|
||||
model = completionmodel.CompletionModel()
|
||||
cats = [mock.Mock(spec=['set_pattern'])] * 3
|
||||
cats = [mock.Mock(spec=['set_pattern', 'layoutChanged'])] * 3
|
||||
for c in cats:
|
||||
c.set_pattern = mock.Mock()
|
||||
model.add_category(c)
|
||||
|
Loading…
Reference in New Issue
Block a user