Don't crash completion with auto-open/show False.

If both are false, the selectionModel may be None.
In this case, don't try to move the index.
Resolves #1722.
This commit is contained in:
Ryan Roden-Corrent 2016-08-01 22:12:13 -04:00
parent 6e2d78b826
commit a393adc6c7
2 changed files with 17 additions and 3 deletions

View File

@ -192,9 +192,13 @@ class CompletionView(QTreeView):
Args:
prev: True for prev item, False for next one.
"""
idx = self._next_idx(prev)
self.selectionModel().setCurrentIndex(idx,
QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
# selmodel can be None if 'show' and 'auto-open' are set to False
# https://github.com/The-Compiler/qutebrowser/issues/1731
selmodel = self.selectionModel()
if (selmodel is not None):
idx = self._next_idx(prev)
selmodel.setCurrentIndex(idx,
QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
def set_model(self, model):
"""Switch completion to a new model.

View File

@ -148,3 +148,13 @@ def test_completion_item_next_prev(tree, count, expected, completionview):
completionview.completion_item_next()
idx = completionview.selectionModel().currentIndex()
assert filtermodel.data(idx) == expected
def test_completion_item_next_prev_no_model(completionview):
"""Test that next/prev won't crash with no model set.
This can happen if completion.show and completion.auto-open are False.
Regression test for issue #1722.
"""
completionview.completion_item_prev()
completionview.completion_item_next()