diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 41ed65d74..364d783f6 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -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. diff --git a/tests/unit/completion/test_completionwidget.py b/tests/unit/completion/test_completionwidget.py index fb1241b2c..badc1fc89 100644 --- a/tests/unit/completion/test_completionwidget.py +++ b/tests/unit/completion/test_completionwidget.py @@ -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()