diff options
author | Florian Bruhin <me@the-compiler.org> | 2022-01-05 16:22:44 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2022-01-05 16:22:44 +0100 |
commit | 0903d9879a157ebd149bd2ebab295f2f2b5e1b29 (patch) | |
tree | 85159034afb6d11539bcf247e37fdd67dccc099c | |
parent | f4714a93000ab208508953b9610042fd4569d538 (diff) | |
parent | 4b5b4ee129933d91ef6f53cb0fa81ec591fb9985 (diff) | |
download | qutebrowser-0903d9879a157ebd149bd2ebab295f2f2b5e1b29.tar.gz qutebrowser-0903d9879a157ebd149bd2ebab295f2f2b5e1b29.zip |
Merge remote-tracking branch 'origin/pr/6619'
-rw-r--r-- | doc/help/settings.asciidoc | 1 | ||||
-rw-r--r-- | qutebrowser/config/configdata.yml | 3 | ||||
-rw-r--r-- | qutebrowser/mainwindow/tabwidget.py | 22 |
3 files changed, 22 insertions, 4 deletions
diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 7435fd31f..b8705749a 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -4388,6 +4388,7 @@ The following placeholders are defined: * `{index}`: Index of this tab. * `{aligned_index}`: Index of this tab padded with spaces to have the same width. +* `{relative_index}`: Index of this tab relative to the current tab. * `{id}`: Internal tab ID of this tab. * `{scroll_pos}`: Page scroll position. * `{host}`: Host of the current web page. diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index c2619ac1f..b0d9c6364 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -2171,6 +2171,7 @@ tabs.title.format: - title_sep - index - aligned_index + - relative_index - id - scroll_pos - host @@ -2190,6 +2191,7 @@ tabs.title.format: * `{index}`: Index of this tab. * `{aligned_index}`: Index of this tab padded with spaces to have the same width. + * `{relative_index}`: Index of this tab relative to the current tab. * `{id}`: Internal tab ID of this tab. * `{scroll_pos}`: Page scroll position. * `{host}`: Host of the current web page. @@ -2210,6 +2212,7 @@ tabs.title.format_pinned: - title_sep - index - aligned_index + - relative_index - id - scroll_pos - host diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py index 07b1e5bef..4ac5e0379 100644 --- a/qutebrowser/mainwindow/tabwidget.py +++ b/qutebrowser/mainwindow/tabwidget.py @@ -136,18 +136,31 @@ class TabWidget(QTabWidget): (fmt is None or ('{' + field + '}') not in fmt)): return + def right_align(text): + return str(text).rjust(len(str(self.count()))) + + def left_align(text): + return str(text).ljust(len(str(self.count()))) + + bar = self.tabBar() + cur_idx = bar.currentIndex() + if idx == cur_idx: + rel_idx = left_align(idx + 1) + " " + else: + rel_idx = " " + right_align(abs(idx - cur_idx)) + fields = self.get_tab_fields(idx) fields['current_title'] = fields['current_title'].replace('&', '&&') fields['index'] = idx + 1 - fields['aligned_index'] = str(idx + 1).rjust(len(str(self.count()))) + fields['aligned_index'] = right_align(idx + 1) + fields['relative_index'] = rel_idx title = '' if fmt is None else fmt.format(**fields) - tabbar = self.tabBar() # Only change the tab title if it changes, setting the tab title causes # a size recalculation which is slow. - if tabbar.tabText(idx) != title: - tabbar.setTabText(idx, title) + if bar.tabText(idx) != title: + bar.setTabText(idx, title) def get_tab_fields(self, idx): """Get the tab field data.""" @@ -305,6 +318,7 @@ class TabWidget(QTabWidget): def _on_current_changed(self, index): """Emit the tab_index_changed signal if the current tab changed.""" self.tabBar().on_current_changed() + self.update_tab_titles() self.tab_index_changed.emit(index, self.count()) @pyqtSlot() |