Expand history completion results if on last index.

When tabbing to the last index of history completion, call expandAll
which will call fetchMore to retrieve more query results, if available.

Calling fetchMore directly will not update the view, and for some
reason self.expand(idx.parent()) and
self.expand(self.model().index(idx.row(), 0)) did not work, so I'm using
expandAll.

Fixes #2841.
This commit is contained in:
Ryan Roden-Corrent 2017-07-23 19:32:24 -04:00
parent 630e9ebd66
commit 32fa1ff1e9
2 changed files with 38 additions and 0 deletions

View File

@ -255,6 +255,10 @@ class CompletionView(QTreeView):
selmodel.setCurrentIndex(
idx, QItemSelectionModel.ClearAndSelect | QItemSelectionModel.Rows)
# if the last item is focused, try to fetch more
if idx.row() == self.model().rowCount(idx.parent()) - 1:
self.expandAll()
count = self.model().count()
if count == 0:
self.hide()

View File

@ -65,6 +65,9 @@ def completionview(qtbot, status_command_stub, config_stub, win_registry,
}
# mock the Completer that the widget creates in its constructor
mocker.patch('qutebrowser.completion.completer.Completer', autospec=True)
mocker.patch(
'qutebrowser.completion.completiondelegate.CompletionItemDelegate',
new=lambda *_: None)
view = completionwidget.CompletionView(win_id=0)
qtbot.addWidget(view)
return view
@ -185,6 +188,37 @@ def test_completion_item_focus_no_model(which, completionview, qtbot):
completionview.completion_item_focus(which)
def test_completion_item_focus_fetch(completionview, qtbot):
"""Test that on_next_prev_item moves the selection properly.
Args:
which: the direction in which to move the selection.
tree: Each list represents a completion category, with each string
being an item under that category.
expected: expected argument from on_selection_changed for each
successive movement. None implies no signal should be
emitted.
"""
model = completionmodel.CompletionModel()
cat = mock.Mock(spec=['layoutChanged', 'layoutAboutToBeChanged',
'canFetchMore', 'fetchMore', 'rowCount', 'index', 'data'])
cat.canFetchMore = lambda *_: True
cat.rowCount = lambda *_: 2
cat.fetchMore = mock.Mock()
model.add_category(cat)
completionview.set_model(model)
# clear the fetchMore call that happens on set_model
cat.reset_mock()
# not at end, fetchMore shouldn't be called
completionview.completion_item_focus('next')
assert not cat.fetchMore.called
# at end, fetchMore should be called
completionview.completion_item_focus('next')
assert cat.fetchMore.called
@pytest.mark.parametrize('show', ['always', 'auto', 'never'])
@pytest.mark.parametrize('rows', [[], ['Aa'], ['Aa', 'Bb']])
@pytest.mark.parametrize('quick_complete', [True, False])