diff --git a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp index 84aba407f74..e867d41b5a6 100644 --- a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp +++ b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp @@ -50,6 +50,7 @@ namespace winrt::TerminalApp::implementation { case ShortcutAction::SetColorScheme: case ShortcutAction::AdjustOpacity: + case ShortcutAction::SendInput: { _RunRestorePreviews(); break; @@ -140,6 +141,27 @@ namespace winrt::TerminalApp::implementation }); } + void TerminalPage::_PreviewSendInput(const Settings::Model::SendInputArgs& args) + { + const auto backup = _restorePreviewFuncs.empty(); + + _ApplyToActiveControls([&](const auto& control) { + // // Stash a copy of the original opacity. + // auto originalOpacity{ control.BackgroundOpacity() }; + + // Apply the new opacity + control.PreviewInput(args.Input()); + + if (backup) + { + _restorePreviewFuncs.emplace_back([=]() { + // On dismiss: + control.PreviewInput(L""); + }); + } + }); + } + // Method Description: // - Handler for the CommandPalette::PreviewAction event. The Command // Palette will raise this even when an action is selected, but _not_ @@ -176,6 +198,11 @@ namespace winrt::TerminalApp::implementation _PreviewAdjustOpacity(args.ActionAndArgs().Args().try_as()); break; } + case ShortcutAction::SendInput: + { + _PreviewSendInput(args.ActionAndArgs().Args().try_as()); + break; + } } // GH#9818 Other ideas for actions that could be preview-able: diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 55021a1e896..7ae426dd738 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -414,6 +414,7 @@ namespace winrt::TerminalApp::implementation void _RunRestorePreviews(); void _PreviewColorScheme(const Microsoft::Terminal::Settings::Model::SetColorSchemeArgs& args); void _PreviewAdjustOpacity(const Microsoft::Terminal::Settings::Model::AdjustOpacityArgs& args); + void _PreviewSendInput(const Microsoft::Terminal::Settings::Model::SendInputArgs& args); winrt::Microsoft::Terminal::Settings::Model::Command _lastPreviewedCommand{ nullptr }; std::vector> _restorePreviewFuncs{}; diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index efac84e2917..026be091854 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -470,4 +470,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation void TSFInputControl::_formatUpdatingHandler(CoreTextEditContext sender, const CoreTextFormatUpdatingEventArgs& /*args*/) { } + + void TSFInputControl::ManuallyDisplayText(const winrt::hstring& text) + { + _focused = !text.empty(); + Canvas().Visibility(text.empty() ? Visibility::Collapsed : Visibility::Visible); + + _inputBuffer.clear(); + // _editContext.NotifyFocusLeave(); + _activeTextStart = 0; + _inComposition = false; + + TextBlock().Text(text); + TextBlock().UpdateLayout(); + TryRedrawCanvas(); + } } diff --git a/src/cascadia/TerminalControl/TSFInputControl.h b/src/cascadia/TerminalControl/TSFInputControl.h index d70eec8301c..b3392f466cd 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.h +++ b/src/cascadia/TerminalControl/TSFInputControl.h @@ -40,6 +40,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation void ClearBuffer(); void TryRedrawCanvas(); + void ManuallyDisplayText(const winrt::hstring& text); + void Close(); // -------------------------------- WinRT Events --------------------------------- diff --git a/src/cascadia/TerminalControl/TSFInputControl.idl b/src/cascadia/TerminalControl/TSFInputControl.idl index 6a6f6814f2a..ce274a6eb8a 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.idl +++ b/src/cascadia/TerminalControl/TSFInputControl.idl @@ -31,6 +31,9 @@ namespace Microsoft.Terminal.Control void ClearBuffer(); void TryRedrawCanvas(); + void ManuallyDisplayText(String text); + + void Close(); } } diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 3aeeb35786c..5fa19244882 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -329,6 +329,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - void TermControl::SendInput(const winrt::hstring& wstr) { + PreviewInput(L""); _core.SendInput(wstr); } void TermControl::ClearBuffer(Control::ClearBufferType clearType) @@ -2834,4 +2835,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation return _core.OwningHwnd(); } + void TermControl::PreviewInput(const winrt::hstring& text) + { + TSFInputControl().ManuallyDisplayText(text); + } + } diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index fdb10e9b978..06124c37da3 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -41,6 +41,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation Windows::Foundation::Size CharacterDimensions() const; Windows::Foundation::Size MinimumSize(); float SnapDimensionToGrid(const bool widthOrHeight, const float dimension); + void PreviewInput(const winrt::hstring& text); void WindowVisibilityChanged(const bool showOrHide); diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl index b221cc85cd4..95d5e5780de 100644 --- a/src/cascadia/TerminalControl/TermControl.idl +++ b/src/cascadia/TerminalControl/TermControl.idl @@ -85,5 +85,7 @@ namespace Microsoft.Terminal.Control // opacity set by the settings should call this instead. Double BackgroundOpacity { get; }; + void PreviewInput(String text); + } }