Merge branch 'rcorre-fix_completion_crashes'
This commit is contained in:
commit
b51640f26d
@ -30,7 +30,7 @@ from PyQt5.QtCore import (pyqtSlot, pyqtSignal, Qt, QItemSelectionModel,
|
||||
from qutebrowser.config import config, style
|
||||
from qutebrowser.completion import completiondelegate
|
||||
from qutebrowser.completion.models import base
|
||||
from qutebrowser.utils import qtutils, objreg, utils, usertypes
|
||||
from qutebrowser.utils import objreg, utils, usertypes
|
||||
from qutebrowser.commands import cmdexc, cmdutils
|
||||
|
||||
|
||||
@ -192,9 +192,17 @@ class CompletionView(QTreeView):
|
||||
Args:
|
||||
prev: True for prev item, False for next one.
|
||||
"""
|
||||
# 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 None:
|
||||
return
|
||||
|
||||
idx = self._next_idx(prev)
|
||||
qtutils.ensure_valid(idx)
|
||||
self.selectionModel().setCurrentIndex(
|
||||
if not idx.isValid():
|
||||
return
|
||||
|
||||
selmodel.setCurrentIndex(
|
||||
idx, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
|
||||
|
||||
def set_model(self, model):
|
||||
|
@ -119,6 +119,8 @@ def test_maybe_resize_completion(completionview, config_stub, qtbot):
|
||||
([['Aa'], []], -1, 'Aa'),
|
||||
([['Aa'], [], []], 1, 'Aa'),
|
||||
([['Aa'], [], []], -1, 'Aa'),
|
||||
([[]], 1, None),
|
||||
([[]], -1, None),
|
||||
])
|
||||
def test_completion_item_next_prev(tree, count, expected, completionview):
|
||||
"""Test that on_next_prev_item moves the selection properly.
|
||||
@ -146,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()
|
||||
|
Loading…
Reference in New Issue
Block a user