Skip to content

Commit

Permalink
Add find item to tab menu (#13055)
Browse files Browse the repository at this point in the history
## Summary of the Pull Request

Add `Find` to tab context menu as describe in issue #5633.

## PR Checklist
* [x] Closes #5633
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA

## Detailed Description of the Pull Request / Additional comments

Just wanted to solve `Easy Starter` issue, so any corrections/suggestions welcome. There's a couple of points I'm not sure of
* Placement of item within menu, currently it's at the end before close tab block.
* Should it be named longer, something like `Find in Tab` of just `Find` is fine?
* The workaround for focus similar to tab rename is a bit annoying, especially because it required adding a method to `TermControl` but without it find window obviously opens without focus which is bad.

## Validation Steps Performed

Open menu, press menu item try to find things via opened find dialog.

(cherry picked from commit b851b0d)
Service-Card-Id: 83524184
Service-Version: 1.14
  • Loading branch information
Predelnik authored and DHowett committed Jun 30, 2022
1 parent a224424 commit 31757a4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@
<data name="ExportSuccess" xml:space="preserve">
<value>Successfully exported terminal content</value>
</data>
<data name="FindText" xml:space="preserve">
<value>Find</value>
</data>
<data name="PlainText" xml:space="preserve">
<value>Plain Text</value>
</data>
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ namespace winrt::TerminalApp::implementation
}
});

newTabImpl->FindRequested([weakTab, weakThis{ get_weak() }]() {
auto page{ weakThis.get() };
auto tab{ weakTab.get() };

if (page && tab)
{
page->_Find();
}
});

auto tabViewItem = newTabImpl->TabViewItem();
_tabView.TabItems().Append(tabViewItem);

Expand Down
20 changes: 19 additions & 1 deletion src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,23 @@ namespace winrt::TerminalApp::implementation
exportTabMenuItem.Icon(exportTabSymbol);
}

Controls::MenuFlyoutItem findMenuItem;
{
// "Split Tab"
Controls::FontIcon findSymbol;
findSymbol.FontFamily(Media::FontFamily{ L"Segoe Fluent Icons, Segoe MDL2 Assets" });
findSymbol.Glyph(L"\xF78B"); // SearchMedium

findMenuItem.Click([weakThis](auto&&, auto&&) {
if (auto tab{ weakThis.get() })
{
tab->_FindRequestedHandlers();
}
});
findMenuItem.Text(RS_(L"FindText"));
findMenuItem.Icon(findSymbol);
}

// Build the menu
Controls::MenuFlyout contextMenuFlyout;
Controls::MenuFlyoutSeparator menuSeparator;
Expand All @@ -1281,6 +1298,7 @@ namespace winrt::TerminalApp::implementation
contextMenuFlyout.Items().Append(duplicateTabMenuItem);
contextMenuFlyout.Items().Append(splitTabMenuItem);
contextMenuFlyout.Items().Append(exportTabMenuItem);
contextMenuFlyout.Items().Append(findMenuItem);
contextMenuFlyout.Items().Append(menuSeparator);

// GH#5750 - When the context menu is dismissed with ESC, toss the focus
Expand All @@ -1291,7 +1309,7 @@ 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())
if (!tab->_headerControl.InRename() && !tab->GetActiveTerminalControl().SearchBoxEditInFocus())
{
tab->_RequestFocusActiveControlHandlers();
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ namespace winrt::TerminalApp::implementation
WINRT_CALLBACK(TabRaiseVisualBell, winrt::delegate<>);
WINRT_CALLBACK(DuplicateRequested, winrt::delegate<>);
WINRT_CALLBACK(SplitTabRequested, winrt::delegate<>);
WINRT_CALLBACK(FindRequested, winrt::delegate<>);
WINRT_CALLBACK(ExportTabRequested, winrt::delegate<>);
TYPED_EVENT(TaskbarProgressChanged, IInspectable, IInspectable);

Expand Down
14 changes: 14 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
}

// Method Description:
// Find if search box text edit currently is in focus
// Return Value:
// - true, if search box text edit is in focus
bool TermControl::SearchBoxEditInFocus() const
{
if (!_searchBox)
{
return false;
}

return _searchBox->TextBox().FocusState() == FocusState::Keyboard;
}

// Method Description:
// - Search text in text buffer. This is triggered if the user click
// search button or press enter.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void SearchMatch(const bool goForward);

bool SearchBoxEditInFocus() const;

bool OnDirectKeyEvent(const uint32_t vkey, const uint8_t scanCode, const bool down);

bool OnMouseWheel(const Windows::Foundation::Point location, const int32_t delta, const bool leftButtonDown, const bool midButtonDown, const bool rightButtonDown);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace Microsoft.Terminal.Control
void ScrollViewport(Int32 viewTop);

void CreateSearchBoxControl();
Boolean SearchBoxEditInFocus();

void SearchMatch(Boolean goForward);

Expand Down

0 comments on commit 31757a4

Please sign in to comment.