mirror of
https://github.com/microsoft/terminal.git
synced 2026-07-08 18:16:28 +00:00
Always use MRU tab focus on tab close regardless of TabSwitcherMode (#20272)
## 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
This commit is contained in:
@@ -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<int32_t>(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
|
||||
|
||||
Reference in New Issue
Block a user