Focus tabs to the right-not left-when the active tab is closed (#18022)

Closes #17244
This commit is contained in:
Michael Xu 2024-10-10 20:08:03 -04:00 committed by GitHub
parent 18d86bca09
commit d0e94365d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -491,14 +491,14 @@ namespace winrt::TerminalApp::implementation
// 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 left, within the bounds of how many tabs we have.
// 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 A (now in index 0)
// * C (tabIndex=2): We'll want to focus tab B (now in index 1)
// * 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 - 1, 0, _tabs.Size() - 1);
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) };