Repository: microsoft/terminal (language: cpp)

Issue:
Alt-Space suppressed when Settings is the only tab
### Windows Terminal version

1.15.2875.0

### Windows build number

22621.819

### Other Software

_No response_

### Steps to reproduce

Open settings and close all other tabs.
Close and reopen terminal (now settings should be the only tab)
Type Alt-Space


### Expected Behavior

The alt-space menu, which includes eg Close

### Actual Behavior

Nothing. When settings is the only tab on startup, alt-space seems to be ignored.

This is a fairly minor bug, except it's the quickest way to close the settings and terminal with the keyboard. The only other way I know is Alt-F4. And of cousre, the menu is useful for other things like moving with the keyboard.

When settings is not the only tab open, alt-space seems to (mostly?) work. And it works on other tabs.


Discussion / hints:
Thanks for the report! I think we actually fixed this in #14221, which should be in a coming servicing release.

/dup #14217
Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Oh, I meant #11970. I'm sorry.
Curious that it still repros for you...
> is the only tab 

is apparently doing a lot of work in this post
Oh I see. THIS IS WEIRD.

If an element in the SUI has focus, then this doesn't repro. Actually, this doesn't repro if _any_ element has focus. But in the specific case where you open the SUI, then close a terminal tab, then the focus is _somewhere_ where alt+space isn't hooked up. 
This issue has been marked as duplicate and has not had any activity for **1 day**. It will be closed for housekeeping purposes.
I also have a default profile open when I press alt+space after closing the tab and click on the titlebar.
Tested at commit 4c7879bfb5745702738d37a5e1e50e22cbba4961
https://user-images.githubusercontent.com/45919738/213252168-05a796c4-326b-4c81-95e3-0ac5c64411f4.mp4


You can repro this by clicking in one of the two red lined areas. 

<img width="1196" alt="image" src="https://user-images.githubusercontent.com/2086722/231022086-374d6d7b-4799-4f44-b153-f2ba7ea1a444.png">

for keyboard folks tabbing focus to anything on the page makes that key combo work

Fix patch:
diff --git a/src/cascadia/TerminalApp/TerminalWindow.cpp b/src/cascadia/TerminalApp/TerminalWindow.cpp
index f8a906b55a6..39fa6d1b58e 100644
--- a/src/cascadia/TerminalApp/TerminalWindow.cpp
+++ b/src/cascadia/TerminalApp/TerminalWindow.cpp
@@ -900,6 +900,12 @@ namespace winrt::TerminalApp::implementation
                     if (!focusedObject)
                     {
                         focusedObject = winrt::Windows::UI::Xaml::Media::VisualTreeHelper::GetParent(focusedElement);
+
+                        // We were unable to find a focused object. Default to the xaml root so that the alt+space menu still works.
+                        if (!focusedObject)
+                        {
+                            focusedObject = _root.try_as<IInspectable>();
+                        }
                     }
                 }
                 else
@@ -908,6 +914,7 @@ namespace winrt::TerminalApp::implementation
                 }
             } while (focusedObject);
         }
+
         return false;
     }
 


Test patch: