Correct widget behavior when there is no completion

This commit is contained in:
Marshall Lochbaum 2016-08-09 13:03:38 -04:00
parent b2067ef186
commit d98c81c9d6
3 changed files with 22 additions and 13 deletions

View File

@ -252,16 +252,13 @@ class Completer(QObject):
# anything (yet)
# FIXME complete searches
# https://github.com/The-Compiler/qutebrowser/issues/32
completion.hide()
completion.set_model(None)
return
model = self._get_new_completion(parts, self._cursor_part)
if model != self._model():
if model is None:
completion.hide()
else:
completion.set_model(model)
completion.set_model(model)
if model is None:
log.completion.debug("No completion model for {}.".format(parts))

View File

@ -47,6 +47,7 @@ class CompletionView(QTreeView):
_height_perc: Either None or a percentage if height should be relative.
_delegate: The item delegate used.
_column_widths: A list of column widths, in percent.
_active: Whether a selection is active.
Signals:
resize_completion: Emitted when the completion should be resized.
@ -112,6 +113,7 @@ class CompletionView(QTreeView):
# objreg.get('config').changed.connect(self.init_command_completion)
self._column_widths = base.BaseCompletionModel.COLUMN_WIDTHS
self._active = False
self._delegate = completiondelegate.CompletionItemDelegate(self)
self.setItemDelegate(self._delegate)
@ -187,6 +189,8 @@ class CompletionView(QTreeView):
Args:
which: 'next' or 'prev'
"""
if not self._active:
return
selmodel = self.selectionModel()
idx = self._next_idx(which == 'prev')
@ -207,22 +211,28 @@ class CompletionView(QTreeView):
Args:
model: The model to use.
"""
if (config.get('completion', 'auto-open') and
config.get('completion', 'show')):
self.show()
else:
if model is None:
self._active = False
self.hide()
return
old_model = self.model()
sel_model = self.selectionModel()
self.setModel(model)
self._active = True
if sel_model is not None:
sel_model.deleteLater()
if old_model is not None:
old_model.deleteLater()
if (config.get('completion', 'auto-open') and
config.get('completion', 'show')):
self.show()
else:
self.hide()
for i in range(model.rowCount()):
self.expand(model.index(i, 0))
@ -258,6 +268,8 @@ class CompletionView(QTreeView):
def selectionChanged(self, selected, deselected):
"""Extend selectionChanged to call completers selection_changed."""
if not self._active:
return
super().selectionChanged(selected, deselected)
self.selection_changed.emit(selected)

View File

@ -199,12 +199,12 @@ def test_update_completion(txt, expected, status_command_stub, completer_obj,
# this test uses | as a placeholder for the current cursor position
_set_cmd_prompt(status_command_stub, txt)
completer_obj.schedule_completion_update()
assert completion_widget_stub.set_model.call_count == 1
arg = completion_widget_stub.set_model.call_args[0][0]
# the outer model is just for sorting; srcmodel is the completion model
if expected is None:
assert not completion_widget_stub.set_model.called
assert arg == expected
else:
assert completion_widget_stub.set_model.call_count == 1
arg = completion_widget_stub.set_model.call_args[0][0]
# the outer model is just for sorting; srcmodel is the completion model
assert arg.srcmodel.kind == expected