From 8824b02a782ebc0dc9843620905cc7e004f1e29e Mon Sep 17 00:00:00 2001 From: Anshika Jain Date: Tue, 23 Jun 2026 23:50:08 +0530 Subject: [PATCH] Always use MRU tab focus on tab close regardless of TabSwitcherMode (#20272) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Always focus the MRU (most recently used) tab when closing the current tab, regardless of TabSwitcherMode setting. ## References Fixes #19819 ## Detailed Description Removed the `TabSwitcherMode` check in `_RemoveTab` (TabManagement.cpp) so tab-close focus behavior is always MRU-based, decoupling it from the tab switcher preference as noted by @DHowett. ## Validation Steps - Opened 3 tabs, navigated Tab3 → Tab1, closed Tab1 - With fix: Tab3 focused (MRU) - Without fix: Tab2 focused (next in order) ## PR Checklist Closes #19819 --- src/cascadia/TerminalApp/TabManagement.cpp | 36 ++-------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 70d5d5eb8e..3a96635d43 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -541,40 +541,10 @@ namespace winrt::TerminalApp::implementation // 1. We want to customize this behavior (e.g., use MRU logic) // 2. In fullscreen (GH#5799) and focus (GH#7916) modes the _OnTabItemsChanged is not fired // 3. When rearranging tabs (GH#7916) _OnTabItemsChanged is suppressed - const auto tabSwitchMode = _settings.GlobalSettings().TabSwitcherMode(); - if (tabSwitchMode == TabSwitcherMode::MostRecentlyUsed) - { - const auto newSelectedTab = _mruTabs.GetAt(0); - _UpdatedSelectedTab(newSelectedTab); - _tabView.SelectedItem(newSelectedTab.TabViewItem()); - } - else - { - // We can't use - // auto selectedIndex = _tabView.SelectedIndex(); - // Because this will always return -1 in this scenario unfortunately. - // - // So, what we're going to try to do is move the focus to the tab - // to the right, within the bounds of how many tabs we have. - // - // EX: we have 4 tabs: [A, B, C, D]. If we close: - // * A (tabIndex=0): We'll want to focus tab B (now in index 0) - // * B (tabIndex=1): We'll want to focus tab C (now in index 1) - // * C (tabIndex=2): We'll want to focus tab D (now in index 2) - // * D (tabIndex=3): We'll want to focus tab C (now in index 2) - const auto newSelectedIndex = std::clamp(tabIndex, 0, _tabs.Size() - 1); - // _UpdatedSelectedTab will do the work of setting up the new tab as - // the focused one, and unfocusing all the others. - auto newSelectedTab{ _tabs.GetAt(newSelectedIndex) }; - _UpdatedSelectedTab(newSelectedTab); - - // Also, we need to _manually_ set the SelectedItem of the tabView - // here. If we don't, then the TabView will technically not have a - // selected item at all, which can make things like ClosePane not - // work correctly. - _tabView.SelectedItem(newSelectedTab.TabViewItem()); - } + const auto newSelectedTab = _mruTabs.GetAt(0); + _UpdatedSelectedTab(newSelectedTab); + _tabView.SelectedItem(newSelectedTab.TabViewItem()); } // GH#5559 - If we were in the middle of a drag/drop, end it by clearing