Skip to content

Commit

Permalink
Don't dismiss the command palette when the new tab menu closes (#15340)
Browse files Browse the repository at this point in the history
Transient UIs are hard.

Regressed in #15077.

Closes #15305

(cherry picked from commit 1bf2fcb)
Service-Card-Id: 89193705
Service-Version: 1.18
  • Loading branch information
zadjii-msft authored and DHowett committed May 12, 2023
1 parent 9909b89 commit 704be80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,10 @@ namespace winrt::TerminalApp::implementation
});
// Necessary for fly-out sub items to get focus on a tab before collapsing. Related to #15049
newTabFlyout.Closing([this](auto&&, auto&&) {
_FocusCurrentTab(true);
if (!_commandPaletteIs(Visibility::Visible))
{
_FocusCurrentTab(true);
}
});
_newTabButton.Flyout(newTabFlyout);
}
Expand Down Expand Up @@ -1448,9 +1451,10 @@ namespace winrt::TerminalApp::implementation
return;
}

if (const auto p = CommandPaletteElement(); p && p.Visibility() == Visibility::Visible && cmd.ActionAndArgs().Action() != ShortcutAction::ToggleCommandPalette)
if (_commandPaletteIs(Visibility::Visible) &&
cmd.ActionAndArgs().Action() != ShortcutAction::ToggleCommandPalette)
{
p.Visibility(Visibility::Collapsed);
CommandPaletteElement().Visibility(Visibility::Collapsed);
}

// Let's assume the user has bound the dead key "^" to a sendInput command that sends "b".
Expand Down Expand Up @@ -1782,6 +1786,11 @@ namespace winrt::TerminalApp::implementation

return _loadCommandPaletteSlowPath();
}
bool TerminalPage::_commandPaletteIs(WUX::Visibility visibility)
{
const auto p = CommandPaletteElement();
return p && p.Visibility() == visibility;
}

CommandPalette TerminalPage::_loadCommandPaletteSlowPath()
{
Expand All @@ -1793,7 +1802,7 @@ namespace winrt::TerminalApp::implementation
// When the visibility of the command palette changes to "collapsed",
// the palette has been closed. Toss focus back to the currently active control.
p.RegisterPropertyChangedCallback(UIElement::VisibilityProperty(), [this](auto&&, auto&&) {
if (CommandPaletteElement().Visibility() == Visibility::Collapsed)
if (_commandPaletteIs(Visibility::Collapsed))
{
_FocusActiveControl(nullptr, nullptr);
}
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ namespace winrt::TerminalApp::implementation
winrt::fire_and_forget _NewTerminalByDrop(const Windows::Foundation::IInspectable&, winrt::Windows::UI::Xaml::DragEventArgs e);

__declspec(noinline) CommandPalette _loadCommandPaletteSlowPath();
bool _commandPaletteIs(winrt::Windows::UI::Xaml::Visibility visibility);

winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowDialogHelper(const std::wstring_view& name);

void _ShowAboutDialog();
Expand Down

0 comments on commit 704be80

Please sign in to comment.