summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoofar <toofar@spalge.com>2023-12-22 18:58:09 +1300
committertoofar <toofar@spalge.com>2024-01-06 20:52:47 +1300
commitdcee69f050ff5206eb68bcef9f2412ec3cbb152c (patch)
tree016213a0cf69228907a26389e30c2602ee83962d
parentba9aee92f45f8a183c1e1d70420b853cb00871e5 (diff)
downloadqutebrowser-dcee69f050ff5206eb68bcef9f2412ec3cbb152c.tar.gz
qutebrowser-dcee69f050ff5206eb68bcef9f2412ec3cbb152c.zip
Avoid tab title updates while updating tree visibility
When we are hiding or showing a tree group `render()` will reflect the `collapsed` state right away. But while `update_tree_tab_visibility()` goes and adds and removes the tabs from the tab widget one by one we get called on each tab removal (via `tabRemoved()` -> `update_tab_title()` -> `get_tab_fields()`). While each of those tab removals is happening there are more tabs in the widget than are returned by `render()` which can cause issues in this code due to the mismatch. So add an attribute and context manager to avoid tab title updates while `update_tree_tab_visibility()` is doing its things, since it goes ahead and updates all the tab titles right afterwards anyway.
-rw-r--r--qutebrowser/mainwindow/tabwidget.py13
-rw-r--r--qutebrowser/mainwindow/treetabwidget.py5
2 files changed, 16 insertions, 2 deletions
diff --git a/qutebrowser/mainwindow/tabwidget.py b/qutebrowser/mainwindow/tabwidget.py
index 066058f2c..4dfdb541b 100644
--- a/qutebrowser/mainwindow/tabwidget.py
+++ b/qutebrowser/mainwindow/tabwidget.py
@@ -65,6 +65,7 @@ class TabWidget(QTabWidget):
self.setDocumentMode(True)
self.setUsesScrollButtons(True)
bar.setDrawBase(False)
+ self._tab_title_update_disabled = False
self._init_config()
config.instance.changed.connect(self._init_config)
@@ -136,6 +137,9 @@ class TabWidget(QTabWidget):
field: A field name which was updated. If given, the title
is only set if the given field is in the template.
"""
+ if self._tab_title_update_disabled:
+ return
+
assert idx != -1
tab = self._tab_by_idx(idx)
assert tab is not None
@@ -253,8 +257,17 @@ class TabWidget(QTabWidget):
bar.setVisible(True)
bar.setUpdatesEnabled(True)
+ @contextlib.contextmanager
+ def _disable_tab_title_updates(self):
+ self._tab_title_update_disabled = True
+ yield
+ self._tab_title_update_disabled = False
+
def update_tab_titles(self):
"""Update all texts."""
+ if self._tab_title_update_disabled:
+ return
+
with self._toggle_visibility():
for idx in range(self.count()):
self.update_tab_title(idx)
diff --git a/qutebrowser/mainwindow/treetabwidget.py b/qutebrowser/mainwindow/treetabwidget.py
index d3d77d0eb..83a409b2a 100644
--- a/qutebrowser/mainwindow/treetabwidget.py
+++ b/qutebrowser/mainwindow/treetabwidget.py
@@ -107,6 +107,7 @@ class TreeTabWidget(TabWidget):
def tree_tab_update(self):
"""Update titles and positions."""
- self.update_tree_tab_visibility()
- self.update_tree_tab_positions()
+ with self._disable_tab_title_updates():
+ self.update_tree_tab_visibility()
+ self.update_tree_tab_positions()
self.update_tab_titles()