From b192164f2e663dc96e697e369654ec79dc529bb3 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Sat, 18 Aug 2018 19:44:51 +1200 Subject: [PATCH] Don't alphabetically sort tab completion. `ListCategory` sorts its completion by default, we are already building the categories in the right order so don't need that. The test tests the case of where you have 11 tabs and if the model was sorted the tabs with index 10 and 11 would be sorted before the one with index 2. The `random.sample` bit for the tab url and title is to also make sure the model isn't being sorted on those columns, whithout haveng to write and all ten lines. --- qutebrowser/completion/models/miscmodels.py | 4 +-- tests/unit/completion/test_models.py | 30 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py index 35beb24de..74b75aeb1 100644 --- a/qutebrowser/completion/models/miscmodels.py +++ b/qutebrowser/completion/models/miscmodels.py @@ -122,8 +122,8 @@ def _buffer(skip_win_id=None): tabs.append(("{}/{}".format(win_id, idx + 1), tab.url().toDisplayString(), tabbed_browser.widget.page_title(idx))) - cat = listcategory.ListCategory("{}".format(win_id), tabs, - delete_func=delete_buffer) + cat = listcategory.ListCategory( + str(win_id), tabs, delete_func=delete_buffer, sort=False) model.add_category(cat) return model diff --git a/tests/unit/completion/test_models.py b/tests/unit/completion/test_models.py index a8c7d9425..8d16b4142 100644 --- a/tests/unit/completion/test_models.py +++ b/tests/unit/completion/test_models.py @@ -20,6 +20,8 @@ """Tests for completion models.""" import collections +import random +import string from datetime import datetime import pytest @@ -593,6 +595,34 @@ def test_tab_completion_delete(qtmodeltester, fake_web_tab, app_stub, QUrl('https://duckduckgo.com')] +def test_tab_completion_not_sorted(qtmodeltester, fake_web_tab, app_stub, + win_registry, tabbed_browser_stubs): + """Ensure that the completion row order is the same as tab index order. + + Would be violated for more than 9 tabs if the completion was being + alphabetically sorted on the first column, or the others. + """ + expected = [] + for idx in range(1, 11): + url = "".join(random.sample(string.ascii_letters, 12)) + title = "".join(random.sample(string.ascii_letters, 12)) + expected.append(("0/{}".format(idx), url, title)) + + tabbed_browser_stubs[0].widget.tabs = [ + fake_web_tab(QUrl(tab[1]), tab[2], idx) + for idx, tab in enumerate(expected) + ] + model = miscmodels.buffer() + model.set_pattern('') + qtmodeltester.data_display_may_return_none = True + qtmodeltester.check(model) + + _check_completions(model, { + '0': expected, + '1': [], + }) + + def test_other_buffer_completion(qtmodeltester, fake_web_tab, app_stub, win_registry, tabbed_browser_stubs, info): tabbed_browser_stubs[0].widget.tabs = [