From 98e4457b8d06a6fedea35836b8633a3bc316ed96 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 20 Nov 2020 18:15:57 +0100 Subject: [PATCH] Add workaround for fetching model data in completion It looks like our views don't update correctly when fetchMore() is called on models, see 32fa1ff and #5897. Since Qt 5.11, Qt actually calls fetchMore in models internally when their view is scrolled to the maximum, so that this condition doesn't actually work properly anymore (thus regressing #2841), because `rowCount()` on the model will return the updated row count after already fetching more data. As a workaround, we now ask the view whether the index below the current one is being displayed, and if not, use the existing expandAll() hack to force it loading new data. This also fixes a crash introduced by the new PgUp/PgDown bindings (`:completion-item-focus {prev,next}-page`): If we're moving towards the end of visible data, PgDown will at some point focus the last visible item. If we then press PgDown again, we move the selected item to an invisible (unloaded) item, thus causing a ZeroDivisionError when trying to get the element height of those items. Fixes #5848 --- qutebrowser/completion/completionwidget.py | 3 ++- tests/unit/completion/test_completionwidget.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py index 1f5304b61..86de688a0 100644 --- a/qutebrowser/completion/completionwidget.py +++ b/qutebrowser/completion/completionwidget.py @@ -331,7 +331,8 @@ class CompletionView(QTreeView): QItemSelectionModel.Rows) # if the last item is focused, try to fetch more - if idx.row() == self.model().rowCount(idx.parent()) - 1: + next_idx = self.indexBelow(idx) + if not self.visualRect(next_idx).isValid(): self.expandAll() count = self.model().count() diff --git a/tests/unit/completion/test_completionwidget.py b/tests/unit/completion/test_completionwidget.py index 356b854c5..c0ef4b47f 100644 --- a/tests/unit/completion/test_completionwidget.py +++ b/tests/unit/completion/test_completionwidget.py @@ -161,6 +161,7 @@ def test_completion_item_focus_no_model(which, completionview, model, qtbot): completionview.completion_item_focus(which) +@pytest.mark.skip("Seems to disagree with reality, see #5897") def test_completion_item_focus_fetch(completionview, model, qtbot): """Test that on_next_prev_item moves the selection properly.