fix(tabs): Fix race condition in show_on_close

This commit is contained in:
Jack Mahoney 2025-07-16 15:21:59 -07:00
parent 008fab41d4
commit 9a90ad2a58
No known key found for this signature in database
GPG Key ID: 9FB0A3A905392E9E
2 changed files with 14 additions and 6 deletions

View File

@ -407,6 +407,7 @@ class TabBar(QTabBar):
# Otherwise, we get "Cannot determine type of "drag_in_progress" in
# TabWidget._toggle_visibility below.
self.drag_in_progress: bool = False
self._closing: bool = False
stylesheet.set_register(self)
self.ensurePolished()
config.instance.changed.connect(self._on_config_changed)
@ -467,6 +468,8 @@ class TabBar(QTabBar):
def on_current_changed(self):
"""Show tab bar when current tab got changed."""
if self._closing:
return
self.maybe_hide() # for fullscreen tabs
if config.val.tabs.show == 'switching':
self.show()
@ -746,11 +749,16 @@ class TabBar(QTabBar):
def tabRemoved(self, idx):
"""Update visibility when a tab was removed."""
super().tabRemoved(idx)
if config.val.tabs.show_on_close and config.val.tabs.show == 'switching':
self.show()
self._auto_hide_timer.start()
else:
self.maybe_hide()
self._closing = True
try:
if (config.val.tabs.show_on_close and
config.val.tabs.show == 'switching'):
self.show()
self._auto_hide_timer.start()
else:
self.maybe_hide()
finally:
self._closing = False
def wheelEvent(self, e):
"""Override wheelEvent to make the action configurable.

View File

@ -208,7 +208,7 @@ class TestTabBarShowOnClose:
config_stub.val.tabs.show = 'switching'
config_stub.val.tabs.show_on_close = True
tab_bar = widget.tabBar()
qtbot.wait(3)
qtbot.wait(1)
assert not tab_bar.isVisible()
widget.removeTab(0)