huh, this seems to work

This commit is contained in:
Mike Griese
2022-03-22 12:31:13 -05:00
parent d97d9f0fcf
commit 1ae63ad3c4
14 changed files with 84 additions and 5 deletions

View File

@@ -860,6 +860,32 @@ namespace winrt::TerminalApp::implementation
args.Handled(true);
}
void TerminalPage::_HandleSearchForText(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
if (args)
{
if (const auto& realArgs = args.ActionArgs().try_as<SearchForTextArgs>())
{
const auto queryUrl = realArgs.QueryUrl();
if (const auto termControl{ _GetActiveControl() })
{
if (termControl.HasSelection())
{
const auto selections{ termControl.SelectedText(true) };
if (selections.Size() == 1) // TODO! should theoretically be able to work for multiple lines of selection
{
const auto finalString = queryUrl + Windows::Foundation::Uri::EscapeComponent(selections.GetAt(0));
winrt::Microsoft::Terminal::Control::OpenHyperlinkEventArgs shortcut{ finalString };
_OpenHyperlinkHandler(termControl, shortcut);
args.Handled(true);
}
}
}
}
}
}
void TerminalPage::_HandleGlobalSummon(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{

View File

@@ -110,6 +110,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
int ViewHeight() const;
int BufferHeight() const;
bool HasSelection() const;
Windows::Foundation::Collections::IVector<winrt::hstring> SelectedText(bool trimTrailingWhitespace) const;
bool BracketedPasteEnabled() const noexcept;
#pragma endregion
@@ -140,9 +143,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool IsVtMouseModeEnabled() const;
Core::Point CursorPosition() const;
bool HasSelection() const;
bool CopyOnSelect() const;
Windows::Foundation::Collections::IVector<winrt::hstring> SelectedText(bool trimTrailingWhitespace) const;
void SetSelectionAnchor(til::point const& position);
void SetEndSelectionPoint(til::point const& position);

View File

@@ -85,9 +85,6 @@ namespace Microsoft.Terminal.Control
void Search(String text, Boolean goForward, Boolean caseSensitive);
Microsoft.Terminal.Core.Color BackgroundColor { get; };
Boolean HasSelection { get; };
IVector<String> SelectedText(Boolean trimTrailingWhitespace);
String HoveredUriText { get; };
Windows.Foundation.IReference<Microsoft.Terminal.Core.Point> HoveredCell { get; };

View File

@@ -146,3 +146,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
WINRT_PROPERTY(bool, FoundMatch);
};
}
namespace winrt::Microsoft::Terminal::Control::factory_implementation
{
BASIC_FACTORY(OpenHyperlinkEventArgs);
}

View File

@@ -35,6 +35,7 @@ namespace Microsoft.Terminal.Control
runtimeclass OpenHyperlinkEventArgs
{
OpenHyperlinkEventArgs(String uri);
String Uri { get; };
}

View File

@@ -19,6 +19,9 @@ namespace Microsoft.Terminal.Control
Int32 ViewHeight { get; };
Int32 BufferHeight { get; };
Boolean HasSelection { get; };
IVector<String> SelectedText(Boolean trimTrailingWhitespace);
Boolean BracketedPasteEnabled { get; };
Microsoft.Terminal.TerminalConnection.ConnectionState ConnectionState { get; };

View File

@@ -2754,6 +2754,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _core.Opacity();
}
bool TermControl::HasSelection() const
{
return _core.HasSelection();
}
Windows::Foundation::Collections::IVector<winrt::hstring> TermControl::SelectedText(bool trimTrailingWhitespace) const
{
return _core.SelectedText(trimTrailingWhitespace);
}
// Method Description:
// - Called when the core raises a FoundMatch event. That's done in response
// to us starting a search query with ControlCore::Search.

View File

@@ -56,6 +56,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
int ViewHeight() const;
int BufferHeight() const;
bool HasSelection() const;
Windows::Foundation::Collections::IVector<winrt::hstring> SelectedText(bool trimTrailingWhitespace) const;
bool BracketedPasteEnabled() const noexcept;
double BackgroundOpacity() const;

View File

@@ -65,6 +65,7 @@ static constexpr std::string_view IdentifyWindowKey{ "identifyWindow" };
static constexpr std::string_view IdentifyWindowsKey{ "identifyWindows" };
static constexpr std::string_view RenameWindowKey{ "renameWindow" };
static constexpr std::string_view OpenWindowRenamerKey{ "openWindowRenamer" };
static constexpr std::string_view SearchForTextKey{ "searchWeb" };
static constexpr std::string_view GlobalSummonKey{ "globalSummon" };
static constexpr std::string_view QuakeModeKey{ "quakeMode" };
static constexpr std::string_view FocusPaneKey{ "focusPane" };
@@ -376,6 +377,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::IdentifyWindows, RS_(L"IdentifyWindowsCommandKey") },
{ ShortcutAction::RenameWindow, RS_(L"ResetWindowNameCommandKey") },
{ ShortcutAction::OpenWindowRenamer, RS_(L"OpenWindowRenamerCommandKey") },
{ ShortcutAction::SearchForText, L"" }, // Intentionally omitted, must be generated by GenerateName
{ ShortcutAction::GlobalSummon, L"" }, // Intentionally omitted, must be generated by GenerateName
{ ShortcutAction::QuakeMode, RS_(L"QuakeModeCommandKey") },
{ ShortcutAction::FocusPane, L"" }, // Intentionally omitted, must be generated by GenerateName

View File

@@ -35,6 +35,7 @@
#include "PrevTabArgs.g.cpp"
#include "NextTabArgs.g.cpp"
#include "RenameWindowArgs.g.cpp"
#include "SearchForTextArgs.g.cpp"
#include "GlobalSummonArgs.g.cpp"
#include "FocusPaneArgs.g.cpp"
#include "ExportBufferArgs.g.cpp"
@@ -703,6 +704,14 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return RS_(L"ResetWindowNameCommandKey");
}
winrt::hstring SearchForTextArgs::GenerateName() const
{
return winrt::hstring{
fmt::format(L"search web with {}",
QueryUrl().c_str())
};
}
winrt::hstring GlobalSummonArgs::GenerateName() const
{
// GH#10210 - Is this action literally the same thing as the `quakeMode`

View File

@@ -37,6 +37,7 @@
#include "PrevTabArgs.g.h"
#include "NextTabArgs.g.h"
#include "RenameWindowArgs.g.h"
#include "SearchForTextArgs.g.h"
#include "GlobalSummonArgs.g.h"
#include "FocusPaneArgs.g.h"
#include "ExportBufferArgs.g.h"
@@ -200,6 +201,12 @@ private:
#define RENAME_WINDOW_ARGS(X) \
X(winrt::hstring, Name, "name", false, L"")
////////////////////////////////////////////////////////////////////////////////
#define SEARCH_FOR_TEXT_ARGS(X) \
X(winrt::hstring, QueryUrl, "queryUrl", false, L"")
//TODO! this should have some validation!
// Maybe in post though. Maybe at runtime make sure QueryUrl starts with "http:"
////////////////////////////////////////////////////////////////////////////////
#define GLOBAL_SUMMON_ARGS(X) \
X(winrt::hstring, Name, "name", false, L"") \
@@ -622,6 +629,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
ACTION_ARGS_STRUCT(RenameWindowArgs, RENAME_WINDOW_ARGS);
ACTION_ARGS_STRUCT(SearchForTextArgs, SEARCH_FOR_TEXT_ARGS);
struct GlobalSummonArgs : public GlobalSummonArgsT<GlobalSummonArgs>
{
ACTION_ARG_BODY(GlobalSummonArgs, GLOBAL_SUMMON_ARGS)

View File

@@ -327,6 +327,11 @@ namespace Microsoft.Terminal.Settings.Model
String Name { get; };
};
[default_interface] runtimeclass SearchForTextArgs : IActionArgs
{
String QueryUrl { get; };
};
[default_interface] runtimeclass GlobalSummonArgs : IActionArgs
{
String Name { get; };

View File

@@ -79,6 +79,7 @@
ON_ALL_ACTIONS(IdentifyWindows) \
ON_ALL_ACTIONS(RenameWindow) \
ON_ALL_ACTIONS(OpenWindowRenamer) \
ON_ALL_ACTIONS(SearchForText) \
ON_ALL_ACTIONS(GlobalSummon) \
ON_ALL_ACTIONS(QuakeMode) \
ON_ALL_ACTIONS(FocusPane) \
@@ -98,6 +99,7 @@
ON_ALL_ACTIONS_WITH_ARGS(CopyText) \
ON_ALL_ACTIONS_WITH_ARGS(ExecuteCommandline) \
ON_ALL_ACTIONS_WITH_ARGS(FindMatch) \
ON_ALL_ACTIONS_WITH_ARGS(SearchForText) \
ON_ALL_ACTIONS_WITH_ARGS(GlobalSummon) \
ON_ALL_ACTIONS_WITH_ARGS(MoveFocus) \
ON_ALL_ACTIONS_WITH_ARGS(MovePane) \

View File

@@ -385,6 +385,13 @@
{ "command": "paste", "keys": "ctrl+shift+v" },
{ "command": "paste", "keys": "shift+insert" },
{ "command": { "action": "searchWeb", "queryUrl": "https://www.bing.com/search?q=" }, "name": "Search for selected text" },
{ "command": { "action": "searchWeb", "queryUrl": "https://www.bing.com/search?q=site%3Astackoverflow.com+" }, "name": "Search StackOverflow" },
{ "command": { "action": "searchWeb", "queryUrl": "https://www.bing.com/search?q=site%3Agithub.com+" }, "name": "Search GitHub" },
{ "command": { "action": "searchWeb", "queryUrl": "https://www.google.com/search?q=" }, "name": "Google for selected text" },
{ "command": { "action": "searchWeb", "queryUrl": "https://www.google.com/search?q=site%3Astackoverflow.com+" }, "name": "Google StackOverflow" },
{ "command": { "action": "searchWeb", "queryUrl": "https://www.google.com/search?q=site%3Agithub.com+" }, "name": "Google GitHub" },
// Scrollback
{ "command": "scrollDown", "keys": "ctrl+shift+down" },
{ "command": "scrollDownPage", "keys": "ctrl+shift+pgdn" },