Skip to content

Commit

Permalink
Sort tab completion properly with more than 9 tabs.
Browse files Browse the repository at this point in the history
`ListCategory` sorts its completion on the first column. The first
column for the tab completion (used by :buffer and :tab-take) is
"win_id/tab_idx". But the tab index wasn't zero padded on the left so if
you had eleven tabs your list would be sorted like:

    0/1
    0/10
    0/11
    0/2
    ...

Which didn't match the order in the tab bar. Now it will.

This changes the shape of a string which callers operate on but they
also all use `int()` and leading zeroes don't change the output of that.

If you have more than nine windows you will get the catagories in the
same jumbled order. Is that something we should worry about?

`log10` throws a ValueError if you pass 0 to it, hence the defensive
coding around `tabbed_browser.widget.count()`, I'm not sure if it could
ever be 0 here but I wouldn't be surprised.
  • Loading branch information
toofar committed Aug 18, 2018
1 parent de8fd25 commit 58d086a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions qutebrowser/completion/models/miscmodels.py
Expand Up @@ -19,6 +19,8 @@

"""Functions that return miscellaneous completion models."""

from math import log10

from qutebrowser.config import configdata
from qutebrowser.utils import objreg, log
from qutebrowser.completion.models import completionmodel, listcategory, util
Expand Down Expand Up @@ -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
for idx in range(num_tabs):
tab = tabbed_browser.widget.widget(idx)
tabs.append(("{}/{}".format(win_id, idx + 1),
label = "{}/{:0{width}}".format(win_id, idx + 1, width=idx_width)
tabs.append((label,
tab.url().toDisplayString(),
tabbed_browser.widget.page_title(idx)))
cat = listcategory.ListCategory("{}".format(win_id), tabs,
Expand Down

0 comments on commit 58d086a

Please sign in to comment.