New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sort tab completion properly with more than 9 tabs. #4140
Conversation
Thanks for the pull request! Note that reviews currently can take a bit longer, as @The-Compiler is busy with exams until September. (Powered by GitMate.io) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but please add a test in test_models.py
to validate the sorting order.
An alternate approach that comes to mind is changing ListCategory._sort
from a bool
to a lambda
, so a custom sorting function could be provided:
diff --git a/qutebrowser/completion/models/listcategory.py b/qutebrowser/completion/models/listcategory.py
index 13bc1e6b2..7db659886 100644
--- a/qutebrowser/completion/models/listcategory.py
+++ b/qutebrowser/completion/models/listcategory.py
@@ -88,6 +88,6 @@ class ListCategory(QSortFilterProxyModel):
elif rightstart and not leftstart:
return False
elif self._sort:
- return left < right
+ return self._sort(left < right)
else:
return False
That might be something worth considering, as it should allow you to solve the issue with > 10 windows.
That being said, I wouldn't worry too much about sorting windows, as there's no clear order to them like there is with tabs.
@@ -117,9 +119,12 @@ def delete_buffer(data): | |||
if tabbed_browser.shutting_down: | |||
continue | |||
tabs = [] | |||
for idx in range(tabbed_browser.widget.count()): | |||
num_tabs = tabbed_browser.widget.count() | |||
idx_width = int(log10(num_tabs)+1) if num_tabs else 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think if num_tabs else 0
is necessary, since the following loop won't run if num_tabs == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed because log10(0)
will throw an error, but I agree it's a little weird...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just do len(str(num_tabs))
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, could you add a small test for the sorting though if possible (maybe one could go in completion.feature)
Seems like all we really need is this and a test: diff --git a/qutebrowser/completion/models/miscmodels.py b/qutebrowser/completion/models/miscmodels.py
index 35beb24de..bf8de194b 100644
--- a/qutebrowser/completion/models/miscmodels.py
+++ b/qutebrowser/completion/models/miscmodels.py
@@ -123,7 +123,7 @@ def _buffer(skip_win_id=None):
tab.url().toDisplayString(),
tabbed_browser.widget.page_title(idx)))
cat = listcategory.ListCategory("{}".format(win_id), tabs,
- delete_func=delete_buffer)
+ delete_func=delete_buffer, sort=False)
model.add_category(cat)
return model |
also, whoever is committing this, while you're at it: Change that |
58d086a
to
da2e38f
Compare
`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.
da2e38f
to
b192164
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
Thanks! |
Don't alphabetically sort tab completion.
ListCategory
was changed to sort completions (on the first column) by default in #3237, most callers that didn't want to be sorted were addressed but the tab completion missed out. This change address that and adds a test to ensure the completion stays in insertion order.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.choices
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 change is