From f3439e201e99f7c42c11953cf4f98eef153ec366 Mon Sep 17 00:00:00 2001 From: Ian O'Neill Date: Mon, 16 Jan 2023 18:18:06 +0000 Subject: [PATCH] Ensure export and find tab context menu items work for unfocused tabs (#14673) ## Summary of the Pull Request Updates the tab event handling so that the "Export Text" and "Find" tab context menu items work when a tab isn't focused. ## PR Checklist * [x] Closes #13948 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx * [ ] Schema updated. * [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx ## Validation Steps Performed Manually tested. --- src/cascadia/TerminalApp/AppActionHandlers.cpp | 5 ++++- src/cascadia/TerminalApp/TabManagement.cpp | 9 +++++---- src/cascadia/TerminalApp/TerminalPage.cpp | 10 +++++----- src/cascadia/TerminalApp/TerminalPage.h | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index a5b17523721..8b2cd7b3637 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -510,7 +510,10 @@ namespace winrt::TerminalApp::implementation void TerminalPage::_HandleFind(const IInspectable& /*sender*/, const ActionEventArgs& args) { - _Find(); + if (const auto activeTab{ _GetFocusedTabImpl() }) + { + _Find(*activeTab); + } args.Handled(true); } diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 97eb581e2fc..7acd7d3f349 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -194,9 +194,9 @@ namespace winrt::TerminalApp::implementation if (page && tab) { - // Passing null args to the ExportBuffer handler will default it - // to prompting for the path - page->_HandleExportBuffer(nullptr, nullptr); + // Passing empty string as the path to export tab will make it + // prompt for the path + page->_ExportTab(*tab, L""); } }); @@ -206,7 +206,8 @@ namespace winrt::TerminalApp::implementation if (page && tab) { - page->_Find(); + page->_SetFocusedTab(*tab); + page->_Find(*tab); } }); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 0d49cefd6aa..cf4f0140a27 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -3160,15 +3160,15 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Called when the user tries to do a search using keybindings. - // This will tell the current focused terminal control to create - // a search box and enable find process. + // This will tell the active terminal control of the passed tab + // to create a search box and enable find process. // Arguments: - // - + // - tab: the tab where the search box should be created // Return Value: // - - void TerminalPage::_Find() + void TerminalPage::_Find(const TerminalTab& tab) { - if (const auto& control{ _GetActiveControl() }) + if (const auto& control{ tab.GetActiveTerminalControl() }) { control.CreateSearchBoxControl(); } diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 03c7a0f2383..9c1705706a0 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -388,7 +388,7 @@ namespace winrt::TerminalApp::implementation void _OnCommandLineExecutionRequested(const IInspectable& sender, const winrt::hstring& commandLine); void _OnSwitchToTabRequested(const IInspectable& sender, const winrt::TerminalApp::TabBase& tab); - void _Find(); + void _Find(const TerminalTab& tab); winrt::Microsoft::Terminal::Control::TermControl _InitControl(const winrt::Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult& settings, const winrt::Microsoft::Terminal::TerminalConnection::ITerminalConnection& connection);