Repository: microsoft/terminal (language: cpp)

Issue:
Focus should move to next tab when closing a tab
<!-- 
🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨

I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING:
1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement.
2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement.
3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number).
4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement.
5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement.

All good? Then proceed!
-->

# Description of the new feature/enhancement

<!-- 
A clear and concise description of what the problem is that the new feature would solve.
Describe why and how a user would use this new functionality (if applicable).
-->

When a tab is closed, focus should move to the tab to the right instead of to the left.

In Firefox and Chrome, when a tab is closed by clicking on 🗙, the cursor naturally lands on the following tab, and the browser shows the content of that tab, allowing the user to close multiple tabs by chain-clicking.

In Terminal, when a tab is closed by clicking on 🗙 (or by any other method), the previous tab is shown even though the cursor is on the following tab. The user must move their cursor from the 🗙, click elsewhere on the tab to preview its contents, and then decide whether to close it. An absentminded user may close important tabs because of this unexpected behavior, particularly because Terminal does not confirm tab closing #6549. Before the user moves their cursor, the tab does not show its usual hover effect, adding to the confusion.

# Proposed technical implementation details (optional)

<!-- 
A clear and concise description of what you want to happen.
-->



Discussion / hints:
Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!


### Closed similar issues:
- [Close Tabs to the Right (#7633)](https://github.com/microsoft/terminal/issues/7633),  similarity score: 0.76

> Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Given that others might have had this problem, I have tried searching for similar (open and closed) issues here and on Google—no luck at all. This issue is not about closing all tabs to the right #5524.

Fix patch:
diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp
index 30b8ec15b81..0eba4511a92 100644
--- a/src/cascadia/TerminalApp/TabManagement.cpp
+++ b/src/cascadia/TerminalApp/TabManagement.cpp
@@ -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) };


Test patch: