From 262d95aae5b1caa2957b113b7fece2d8802a0c56 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 18 Jul 2023 13:47:38 -0500 Subject: [PATCH] [PARENT] try to use GetActiveTerminalControl less in TerminalTab --- src/cascadia/TerminalApp/TerminalTab.cpp | 16 +++++++++++++--- src/cascadia/TerminalApp/TerminalTab.h | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 843ad2227c4..7bb1fee27c9 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -188,6 +188,11 @@ namespace winrt::TerminalApp::implementation return nullptr; } + IPaneContent TerminalTab::GetActiveContent() const + { + return _activePane ? _activePane->GetContent() : nullptr; + } + // Method Description: // - Called after construction of a Tab object to bind event handlers to its // associated Pane and TermControl objects @@ -371,8 +376,8 @@ namespace winrt::TerminalApp::implementation { return RS_(L"MultiplePanes"); } - const auto lastFocusedControl = GetActiveTerminalControl(); - return lastFocusedControl ? lastFocusedControl.Title() : L""; + const auto activeContent = GetActiveContent(); + return activeContent ? activeContent.Title() : L""; } // Method Description: @@ -1448,7 +1453,12 @@ namespace winrt::TerminalApp::implementation // 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->GetActiveTerminalControl().SearchBoxEditInFocus()) + const auto& terminalControl{ tab->GetActiveTerminalControl() }; // maybe null + // If we're + // * NOT in a rename + // * AND (the content isn't a TermControl, OR the term control doesn't have focus in the search box) + if (!tab->_headerControl.InRename() && + (terminalControl == nullptr || !terminalControl.SearchBoxEditInFocus())) { tab->_RequestFocusActiveControlHandlers(); } diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h index a361f2daa6b..4b83813ed39 100644 --- a/src/cascadia/TerminalApp/TerminalTab.h +++ b/src/cascadia/TerminalApp/TerminalTab.h @@ -25,6 +25,7 @@ namespace winrt::TerminalApp::implementation winrt::Microsoft::Terminal::Control::TermControl GetActiveTerminalControl() const; winrt::Microsoft::Terminal::Settings::Model::Profile GetFocusedProfile() const noexcept; + winrt::TerminalApp::IPaneContent GetActiveContent() const; void Focus(winrt::Windows::UI::Xaml::FocusState focusState) override;