Skip to content

Commit d33dd1f

Browse files
Don-VitoDHowett
authored andcommitted
Teach tab to focus terminal after rename (#9162)
## Summary of the Pull Request After rename ends (either by enter or escape) the rename box gets collapsed and the focus moves to the next tab stop in the TabView (e.g., new tab button). To overcome this: * Added RenameEnded event to TabHeaderControl * Forwarded it as RenamerDeactivated from TerminalTab * Registered in the TerminalPage to focus the active control upon RenamerDeactivated if focus didn't move to tab menu. This means, no matter how you close the renamer, the current terminal gains the focus. ## PR Checklist * [x] Closes #9160 * [x] CLA signed. * [ ] Tests added/passed * [ ] Documentation updated. * [ ] Schema updated. * [ ] I've discussed this with core contributors already. (cherry picked from commit 00d1dc9)
1 parent da5ec7b commit d33dd1f

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

src/cascadia/TerminalApp/TabHeaderControl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ namespace winrt::TerminalApp::implementation
106106
// - Hides the rename box and displays the title text block
107107
void TabHeaderControl::_CloseRenameBox()
108108
{
109-
HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed);
110-
HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible);
109+
if (HeaderRenamerTextBox().Visibility() == Windows::UI::Xaml::Visibility::Visible)
110+
{
111+
HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed);
112+
HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible);
113+
_RenameEndedHandlers(*this, nullptr);
114+
}
111115
}
112116
}

src/cascadia/TerminalApp/TabHeaderControl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace winrt::TerminalApp::implementation
2929
OBSERVABLE_GETSET_PROPERTY(bool, BellIndicator, _PropertyChangedHandlers);
3030
OBSERVABLE_GETSET_PROPERTY(uint32_t, ProgressValue, _PropertyChangedHandlers);
3131

32+
TYPED_EVENT(RenameEnded, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
33+
3234
private:
3335
bool _receivedKeyDown{ false };
3436
bool _renameCancelled{ false };

src/cascadia/TerminalApp/TabHeaderControl.idl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ namespace TerminalApp
1919
void BeginRename();
2020

2121
event TitleChangeRequestedArgs TitleChangeRequested;
22+
event Windows.Foundation.TypedEventHandler<Object, Object> RenameEnded;
2223
}
2324
}

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,19 @@ namespace winrt::TerminalApp::implementation
817817
}
818818
});
819819

820+
newTabImpl->TabRenamerDeactivated([weakThis{ get_weak() }](auto&& /*s*/, auto&& /*e*/) {
821+
if (const auto page{ weakThis.get() })
822+
{
823+
if (!page->_newTabButton.Flyout().IsOpen())
824+
{
825+
if (const auto tab{ page->_GetFocusedTab() })
826+
{
827+
tab.Focus(FocusState::Programmatic);
828+
}
829+
}
830+
}
831+
});
832+
820833
if (debugConnection) // this will only be set if global debugging is on and tap is active
821834
{
822835
TermControl newControl{ settings, debugConnection };

src/cascadia/TerminalApp/TerminalTab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ namespace winrt::TerminalApp::implementation
8181
DECLARE_EVENT(ColorSelected, _colorSelected, winrt::delegate<winrt::Windows::UI::Color>);
8282
DECLARE_EVENT(ColorCleared, _colorCleared, winrt::delegate<>);
8383
DECLARE_EVENT(TabRaiseVisualBell, _TabRaiseVisualBellHandlers, winrt::delegate<>);
84+
FORWARDED_TYPED_EVENT(TabRenamerDeactivated, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable, (&_headerControl), RenameEnded);
8485

8586
private:
8687
std::shared_ptr<Pane> _rootPane{ nullptr };

0 commit comments

Comments
 (0)