Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add find item to tab menu #13055

Merged
1 commit merged into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oop - this is find!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry about that, obviously happened during copy-paste 😅

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 @@ -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