From aa6193b0a8c6e1bb74618b06b9e795b7a52ee87b Mon Sep 17 00:00:00 2001 From: Nathan Sprangers Date: Thu, 9 Sep 2021 14:56:51 -0400 Subject: [PATCH] Disable "detach-tab" after closing others Other signals are received too early when closing tabs. ViewContainer::viewRemoved is received after the tab count has been updated. Protect against the "detach-tab" action when only one left. Fixes the following behavior: - Create two tabs - Close one tab - Detach the remaining tab through menu or shortcut - The original window is blank - no terminal display. Adding a tab to it crashes --- src/ViewManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp index 512bdaa5..16e95875 100644 --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -295,6 +295,8 @@ void ViewManager::setupActions() connect(_viewContainer, &TabbedViewContainer::viewAdded, this, &ViewManager::toggleActionsBasedOnState); connect(_viewContainer, &QTabWidget::currentChanged, this, &ViewManager::toggleActionsBasedOnState); + // Let the view container remove the view before counting tabs + connect(_viewContainer, &TabbedViewContainer::viewRemoved, this, &ViewManager::toggleActionsBasedOnState); toggleActionsBasedOnState(); } @@ -445,6 +447,9 @@ void ViewManager::detachActiveView() void ViewManager::detachActiveTab() { + if (_viewContainer->count() < 2) { + return; + } const int currentIdx = _viewContainer->currentIndex(); detachTab(currentIdx); }