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.
This commit is contained in:
Jimmy 2018-08-18 19:44:51 +12:00
parent de8fd25f43
commit b192164f2e
2 changed files with 32 additions and 2 deletions

View File

@ -122,8 +122,8 @@ def _buffer(skip_win_id=None):
tabs.append(("{}/{}".format(win_id, idx + 1), tabs.append(("{}/{}".format(win_id, idx + 1),
tab.url().toDisplayString(), tab.url().toDisplayString(),
tabbed_browser.widget.page_title(idx))) tabbed_browser.widget.page_title(idx)))
cat = listcategory.ListCategory("{}".format(win_id), tabs, cat = listcategory.ListCategory(
delete_func=delete_buffer) str(win_id), tabs, delete_func=delete_buffer, sort=False)
model.add_category(cat) model.add_category(cat)
return model return model

View File

@ -20,6 +20,8 @@
"""Tests for completion models.""" """Tests for completion models."""
import collections import collections
import random
import string
from datetime import datetime from datetime import datetime
import pytest import pytest
@ -593,6 +595,34 @@ def test_tab_completion_delete(qtmodeltester, fake_web_tab, app_stub,
QUrl('https://duckduckgo.com')] 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, def test_other_buffer_completion(qtmodeltester, fake_web_tab, app_stub,
win_registry, tabbed_browser_stubs, info): win_registry, tabbed_browser_stubs, info):
tabbed_browser_stubs[0].widget.tabs = [ tabbed_browser_stubs[0].widget.tabs = [