Repository: microsoft/terminal (language: cpp)

Issue:
Focus starts on titlebar when opening a profile from a nested dropdown entry
### Windows Terminal version

1.17.1023

### Windows build number

10.0.19045.0

### Other Software

_No response_

### Steps to reproduce

Adding a profile like this in wt 1.16.10261.0 starts the profile with keyboard focus on the command shell

When I use the preview version, focus is on the titlebar, so I have to tab 2x to switch to the command shell

```json
            {
                "commandline": "ssh -i \"%USERPROFILE%\\.ssh\\my-super-secret-key.pem\" ec2-user@10.161.0.101",
                "experimental.retroTerminalEffect": true,
                "guid": "{8e690e45-db6d-47c5-919a-68a86077f9dd}",
                "hidden": false,
                "name": "ec2:kpk-my-super-awesome-ec2-name",
                "suppressApplicationTitle": true
            }
```

I am using the fabulous new folders feature
```json
        {
            "type": "folder",
            "name": "ssh",
            "entries": [
                {
                    "profile": "ec2:kpk-my-super-awesome-ec2-name",
                    "type": "profile"
                }
            ]
        }
```



### Expected Behavior

focus in command shell

### Actual Behavior

focus in titlebar


Discussion / hints:
This appears to be a side effect of using folders. When I remove the folder entry from newTabMenu, focus starts in the shell.




INTERESTING

I can totally repro this. That's wild!

Thanks for the report!
If this is in help wanted, I can take a look, as I'm off my regular 9-5 job this week. Bear with me as I haven't built wt yet. (This is from op's personal github account)

Fix patch:
diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp
index 9bfaa4ef381..49ecaeefc19 100644
--- a/src/cascadia/TerminalApp/TerminalPage.cpp
+++ b/src/cascadia/TerminalApp/TerminalPage.cpp
@@ -855,6 +855,10 @@ namespace winrt::TerminalApp::implementation
         newTabFlyout.Opening([this](auto&&, auto&&) {
             _FocusCurrentTab(true);
         });
+        // Necessary for fly-out sub items to get focus on a tab before collapsing. Related to #15049
+        newTabFlyout.Closing([this](auto&&, auto&&) {
+            _FocusCurrentTab(true);
+        });
         _newTabButton.Flyout(newTabFlyout);
     }
 


Test patch: