Skip to content

Commit

Permalink
Don't yeet focus to the control when the tab renamer is opened (#10114)
Browse files Browse the repository at this point in the history
This is a hotfix to #10048. When the tab renamer is opened, we need to make sure to not immediately steal focus from it.

* [x] closes #10112
* [x] I work here
* [x] tested manually
  • Loading branch information
zadjii-msft authored May 18, 2021
1 parent e3d673e commit 24f80bd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/cascadia/TerminalApp/TabHeaderControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ namespace winrt::TerminalApp::implementation
});
}

// Method Description:
// - Returns true if we're in the middle of a tab rename. This is used to
// mitigate GH#10112.
// Arguments:
// - <none>
// Return Value:
// - true if the renamer is open.
bool TabHeaderControl::InRename()
{
return Windows::UI::Xaml::Visibility::Visible == HeaderRenamerTextBox().Visibility();
}

// Method Description:
// - Show the tab rename box for the user to rename the tab title
// - We automatically use the previous title as the initial text of the box
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TabHeaderControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace winrt::TerminalApp::implementation
void RenameBoxLostFocusHandler(winrt::Windows::Foundation::IInspectable const& sender,
winrt::Windows::UI::Xaml::RoutedEventArgs const& e);

bool InRename();

WINRT_CALLBACK(TitleChangeRequested, TerminalApp::TitleChangeRequestedArgs);

WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TabHeaderControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace TerminalApp
TabHeaderControl();
void BeginRename();

Boolean InRename { get; };

TerminalTabStatus TabStatus { get; set; };

event TitleChangeRequestedArgs TitleChangeRequested;
Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,13 @@ namespace winrt::TerminalApp::implementation
contextMenuFlyout.Closed([weakThis](auto&&, auto&&) {
if (auto tab{ weakThis.get() })
{
tab->_RequestFocusActiveControlHandlers();
// GH#10112 - if we're opening the tab renamer, don't
// immediately toss focus to the control. We don't want to steal
// focus from the tab renamer.
if (!tab->_headerControl.InRename())
{
tab->_RequestFocusActiveControlHandlers();
}
}
});
_AppendCloseMenuItems(contextMenuFlyout);
Expand Down

0 comments on commit 24f80bd

Please sign in to comment.