Skip to content

Commit

Permalink
Add find item to tab menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Predelnik committed May 7, 2022
1 parent 0d17769 commit 24f9fe4
Show file tree
Hide file tree
Showing 7 changed files with 48 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
12 changes: 12 additions & 0 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,18 @@ 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 @@ -89,6 +89,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 @@ -61,6 +61,7 @@ namespace Microsoft.Terminal.Control
void ScrollViewport(Int32 viewTop);

void CreateSearchBoxControl();
Boolean SearchBoxEditInFocus();

void SearchMatch(Boolean goForward);

Expand Down

0 comments on commit 24f9fe4

Please sign in to comment.