From cd8bc7c4d60a85d4a240ba771fde3be98eeee52c Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Fri, 28 Feb 2020 13:57:03 -0800 Subject: [PATCH 1/9] korean input seems to work, but now emojis don't work :sadface: --- .../TerminalControl/TSFInputControl.cpp | 27 ++++++++++++------- .../TerminalControl/TSFInputControl.h | 2 ++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index 2e020f1c937..58def54f407 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -18,7 +18,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation { TSFInputControl::TSFInputControl() : _editContext{ nullptr }, - _inComposition{ false } + _inComposition{ false }, + _prevCompositionCompleted{ 0 }, + _currCompositionCompleted{ 0 } { _Create(); } @@ -216,6 +218,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // only need to do work if the current buffer has text if (!_inputBuffer.empty()) { + _currCompositionCompleted = _inputBuffer.length(); _SendAndClearText(); } } @@ -311,13 +314,16 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation length, text); - _textBlock.Text(_inputBuffer); + TextBlock().Text(_inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1)); // If we receive tabbed IME input like emoji, kaomojis, and symbols, send it to the terminal immediately. // They aren't composition, so we don't want to wait for the user to start and finish a composition to send the text. if (!_inComposition) { - _SendAndClearText(); + _compositionCompletedHandlers(_inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1)); + _prevCompositionCompleted = _currCompositionCompleted = range.EndCaretPosition; + TextBlock().Text(L""); + Canvas().Visibility(Visibility::Collapsed); } // Notify the TSF that the update succeeded @@ -343,18 +349,19 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation void TSFInputControl::_SendAndClearText() { // call event handler with data handled by parent - _compositionCompletedHandlers(_inputBuffer); + _compositionCompletedHandlers(_inputBuffer.substr(_prevCompositionCompleted, _currCompositionCompleted - _prevCompositionCompleted)); + _prevCompositionCompleted = _currCompositionCompleted; // clear the buffer for next round - const auto bufferLength = ::base::ClampedNumeric(_inputBuffer.length()); - _inputBuffer.clear(); - _textBlock.Text(L""); + //const auto bufferLength = ::base::ClampedNumeric(_inputBuffer.length()); + //_inputBuffer.clear(); + TextBlock().Text(L""); // Leaving focus before NotifyTextChanged seems to guarantee that the next // composition will send us a CompositionStarted event. - _editContext.NotifyFocusLeave(); - _editContext.NotifyTextChanged({ 0, bufferLength }, 0, { 0, 0 }); - _editContext.NotifyFocusEnter(); + //_editContext.NotifyFocusLeave(); + //_editContext.NotifyTextChanged({ 0, bufferLength }, 0, { 0, 0 }); + //_editContext.NotifyFocusEnter(); // hide the controls until text input starts again _canvas.Visibility(Visibility::Collapsed); diff --git a/src/cascadia/TerminalControl/TSFInputControl.h b/src/cascadia/TerminalControl/TSFInputControl.h index 8438d37bbbc..bf7fd59d9dc 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.h +++ b/src/cascadia/TerminalControl/TSFInputControl.h @@ -78,6 +78,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation bool _inComposition; void _SendAndClearText(); + size_t _prevCompositionCompleted; + size_t _currCompositionCompleted; }; } namespace winrt::Microsoft::Terminal::TerminalControl::factory_implementation From e98d6d4766eecd165d296996ac3402b2929455fd Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Fri, 28 Feb 2020 16:33:46 -0800 Subject: [PATCH 2/9] LOOKIN GUD --- src/cascadia/TerminalControl/TSFInputControl.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index 04f0dd51549..b12e3cf689f 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. +// Copyright (c) Microsoft Corporation. // Licensed under the MIT license. #include "pch.h" @@ -293,7 +293,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // They aren't composition, so we don't want to wait for the user to start and finish a composition to send the text. if (!_inComposition) { - _compositionCompletedHandlers(_inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1)); + _compositionCompletedHandlers(text); _prevCompositionCompleted = _currCompositionCompleted = range.EndCaretPosition; TextBlock().Text(L""); Canvas().Visibility(Visibility::Collapsed); @@ -322,7 +322,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation void TSFInputControl::_SendAndClearText() { // call event handler with data handled by parent - _compositionCompletedHandlers(_inputBuffer.substr(_prevCompositionCompleted, _currCompositionCompleted - _prevCompositionCompleted)); + const auto toSend = _inputBuffer.substr(_prevCompositionCompleted, _currCompositionCompleted - _prevCompositionCompleted); + _compositionCompletedHandlers(toSend); _prevCompositionCompleted = _currCompositionCompleted; // clear the buffer for next round From e9f01c301707adda3e340405a426774b1cedf725 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 3 Mar 2020 13:29:20 -0800 Subject: [PATCH 3/9] cleanup and trying to figure out when to clear the buffer --- .../TerminalControl/TSFInputControl.cpp | 60 +++++++++++-------- .../TerminalControl/TSFInputControl.h | 7 ++- .../TerminalControl/TSFInputControl.xaml | 3 +- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index b12e3cf689f..b918e73b4f7 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -19,8 +19,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation TSFInputControl::TSFInputControl() : _editContext{ nullptr }, _inComposition{ false }, - _prevCompositionCompleted{ 0 }, - _currCompositionCompleted{ 0 } + _activeTextStart{ 0 }, + _activeTextEnd{ 0 } { InitializeComponent(); @@ -94,6 +94,25 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation } } + // Method Description: + // Arguments: + // - sender: not used + // - e: event data + // Return Value: + // - + void TSFInputControl::_KeyDownHandler(winrt::Windows::Foundation::IInspectable const& /*sender*/, + Input::KeyRoutedEventArgs const& e) + { + if (e.OriginalKey() == winrt::Windows::System::VirtualKey::Enter) + { + _inputBuffer.clear(); + const auto bufLen = ::base::ClampedNumeric(_inputBuffer.length()); + _editContext.NotifyFocusLeave(); + _editContext.NotifyTextChanged({ 0, bufLen }, 0, { 0, 0 }); + _editContext.NotifyFocusEnter(); + } + } + // Method Description: // - Handler for LayoutRequested event by CoreEditContext responsible // for returning the current position the IME should be placed @@ -192,7 +211,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // only need to do work if the current buffer has text if (!_inputBuffer.empty()) { - _currCompositionCompleted = _inputBuffer.length(); _SendAndClearText(); } } @@ -281,10 +299,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation { Canvas().Visibility(Visibility::Visible); - const auto length = ::base::ClampSub(range.EndCaretPosition, range.StartCaretPosition); _inputBuffer = _inputBuffer.replace( range.StartCaretPosition, - length, + ::base::ClampSub(range.EndCaretPosition, range.StartCaretPosition), text); TextBlock().Text(_inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1)); @@ -293,10 +310,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // They aren't composition, so we don't want to wait for the user to start and finish a composition to send the text. if (!_inComposition) { - _compositionCompletedHandlers(text); - _prevCompositionCompleted = _currCompositionCompleted = range.EndCaretPosition; - TextBlock().Text(L""); - Canvas().Visibility(Visibility::Collapsed); + _activeTextStart = range.StartCaretPosition; + _SendAndClearText(); } // Notify the TSF that the update succeeded @@ -312,30 +327,23 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation } // Method Description: - // - Sends the currently held text in the input buffer to the parent and - // clears the input buffer and text block for the next round of input. - // Then hides the text block control until the next time text received. + // - Sends the portion of the input buffer that is "active text" to the terminal. + // Then clears the TextBlock and hides it until the next time text is received. // Arguments: // - // Return Value: // - void TSFInputControl::_SendAndClearText() { - // call event handler with data handled by parent - const auto toSend = _inputBuffer.substr(_prevCompositionCompleted, _currCompositionCompleted - _prevCompositionCompleted); - _compositionCompletedHandlers(toSend); - _prevCompositionCompleted = _currCompositionCompleted; - - // clear the buffer for next round - //const auto bufferLength = ::base::ClampedNumeric(_inputBuffer.length()); - //_inputBuffer.clear(); - TextBlock().Text(L""); + _activeTextEnd = _inputBuffer.length(); - // Leaving focus before NotifyTextChanged seems to guarantee that the next - // composition will send us a CompositionStarted event. - //_editContext.NotifyFocusLeave(); - //_editContext.NotifyTextChanged({ 0, bufferLength }, 0, { 0, 0 }); - //_editContext.NotifyFocusEnter(); + const auto text = _inputBuffer.substr(_activeTextStart, _activeTextEnd - _activeTextStart); + + _compositionCompletedHandlers(text); + + _activeTextStart = _activeTextEnd; + + TextBlock().Text(L""); // hide the controls until text input starts again Canvas().Visibility(Visibility::Collapsed); diff --git a/src/cascadia/TerminalControl/TSFInputControl.h b/src/cascadia/TerminalControl/TSFInputControl.h index aa5068a27b2..1e29b04b899 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.h +++ b/src/cascadia/TerminalControl/TSFInputControl.h @@ -47,6 +47,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation DECLARE_EVENT(CompositionCompleted, _compositionCompletedHandlers, TerminalControl::CompositionCompletedEventArgs); private: + friend struct TSFInputControlT; + void _layoutRequestedHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextLayoutRequestedEventArgs const& args); void _compositionStartedHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextCompositionStartedEventArgs const& args); void _compositionCompletedHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextCompositionCompletedEventArgs const& args); @@ -56,6 +58,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation void _selectionUpdatingHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextSelectionUpdatingEventArgs const& args); void _textUpdatingHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextTextUpdatingEventArgs const& args); void _formatUpdatingHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextFormatUpdatingEventArgs const& args); + void _KeyDownHandler(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e); winrt::Windows::UI::Text::Core::CoreTextEditContext::TextRequested_revoker _textRequestedRevoker; winrt::Windows::UI::Text::Core::CoreTextEditContext::SelectionRequested_revoker _selectionRequestedRevoker; @@ -73,8 +76,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation bool _inComposition; void _SendAndClearText(); - size_t _prevCompositionCompleted; - size_t _currCompositionCompleted; + size_t _activeTextStart; + size_t _activeTextEnd; }; } namespace winrt::Microsoft::Terminal::TerminalControl::factory_implementation diff --git a/src/cascadia/TerminalControl/TSFInputControl.xaml b/src/cascadia/TerminalControl/TSFInputControl.xaml index 50c87a6e538..0d742ea30b7 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.xaml +++ b/src/cascadia/TerminalControl/TSFInputControl.xaml @@ -6,7 +6,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="768" - d:DesignWidth="1024"> + d:DesignWidth="1024" + KeyDown="_KeyDownHandler"> Date: Tue, 3 Mar 2020 13:34:45 -0800 Subject: [PATCH 4/9] removed unnecessary var --- src/cascadia/TerminalControl/TSFInputControl.cpp | 13 +++++-------- src/cascadia/TerminalControl/TSFInputControl.h | 1 - 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index b918e73b4f7..940ed1e608a 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -19,8 +19,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation TSFInputControl::TSFInputControl() : _editContext{ nullptr }, _inComposition{ false }, - _activeTextStart{ 0 }, - _activeTextEnd{ 0 } + _activeTextStart{ 0 } { InitializeComponent(); @@ -327,21 +326,19 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation } // Method Description: - // - Sends the portion of the input buffer that is "active text" to the terminal. - // Then clears the TextBlock and hides it until the next time text is received. + // - Send the portion of the textBuffer starting at _activeTextStart to the end of the buffer. + // Then clear the TextBlock and hide it until the next time text is received. // Arguments: // - // Return Value: // - void TSFInputControl::_SendAndClearText() { - _activeTextEnd = _inputBuffer.length(); - - const auto text = _inputBuffer.substr(_activeTextStart, _activeTextEnd - _activeTextStart); + const auto text = _inputBuffer.substr(_activeTextStart, _inputBuffer.length() - _activeTextStart); _compositionCompletedHandlers(text); - _activeTextStart = _activeTextEnd; + _activeTextStart = _inputBuffer.length(); TextBlock().Text(L""); diff --git a/src/cascadia/TerminalControl/TSFInputControl.h b/src/cascadia/TerminalControl/TSFInputControl.h index 1e29b04b899..cf4cfa69e86 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.h +++ b/src/cascadia/TerminalControl/TSFInputControl.h @@ -77,7 +77,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation bool _inComposition; void _SendAndClearText(); size_t _activeTextStart; - size_t _activeTextEnd; }; } namespace winrt::Microsoft::Terminal::TerminalControl::factory_implementation From 7f17c14c764e65d480dca7405499bd43b8b0834a Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 3 Mar 2020 15:14:28 -0800 Subject: [PATCH 5/9] clear input buffer on enter or escape --- .../TerminalControl/TSFInputControl.cpp | 32 +++++++++---------- .../TerminalControl/TSFInputControl.h | 8 ++--- .../TerminalControl/TSFInputControl.idl | 1 + .../TerminalControl/TSFInputControl.xaml | 3 +- src/cascadia/TerminalControl/TermControl.cpp | 6 ++++ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index 940ed1e608a..21aa2dca6e3 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -94,22 +94,21 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation } // Method Description: + // - Clears the input buffer and tells the text server to clear their buffer as well. + // Also clears the TextBlock and sets the active text starting point to 0. // Arguments: - // - sender: not used - // - e: event data + // - // Return Value: // - - void TSFInputControl::_KeyDownHandler(winrt::Windows::Foundation::IInspectable const& /*sender*/, - Input::KeyRoutedEventArgs const& e) + void TSFInputControl::ClearBuffer() { - if (e.OriginalKey() == winrt::Windows::System::VirtualKey::Enter) - { - _inputBuffer.clear(); - const auto bufLen = ::base::ClampedNumeric(_inputBuffer.length()); - _editContext.NotifyFocusLeave(); - _editContext.NotifyTextChanged({ 0, bufLen }, 0, { 0, 0 }); - _editContext.NotifyFocusEnter(); - } + TextBlock().Text(L""); + _inputBuffer.clear(); + _editContext.NotifyFocusLeave(); + _editContext.NotifyTextChanged({ 0, ::base::ClampedNumeric(_inputBuffer.length()) }, 0, { 0, 0 }); + _editContext.NotifyFocusEnter(); + _activeTextStart = 0; + _inComposition = false; } // Method Description: @@ -296,15 +295,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation try { - Canvas().Visibility(Visibility::Visible); - _inputBuffer = _inputBuffer.replace( range.StartCaretPosition, ::base::ClampSub(range.EndCaretPosition, range.StartCaretPosition), text); - TextBlock().Text(_inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1)); - // If we receive tabbed IME input like emoji, kaomojis, and symbols, send it to the terminal immediately. // They aren't composition, so we don't want to wait for the user to start and finish a composition to send the text. if (!_inComposition) @@ -312,6 +307,11 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation _activeTextStart = range.StartCaretPosition; _SendAndClearText(); } + else + { + Canvas().Visibility(Visibility::Visible); + TextBlock().Text(_inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1)); + } // Notify the TSF that the update succeeded args.Result(CoreTextTextUpdatingResult::Succeeded); diff --git a/src/cascadia/TerminalControl/TSFInputControl.h b/src/cascadia/TerminalControl/TSFInputControl.h index cf4cfa69e86..f57925b2c07 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.h +++ b/src/cascadia/TerminalControl/TSFInputControl.h @@ -36,19 +36,16 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation void NotifyFocusEnter(); void NotifyFocusLeave(); + void ClearBuffer(); void Close(); - static void OnCompositionChanged(Windows::UI::Xaml::DependencyObject const&, Windows::UI::Xaml::DependencyPropertyChangedEventArgs const&); - // -------------------------------- WinRT Events --------------------------------- TYPED_EVENT(CurrentCursorPosition, TerminalControl::TSFInputControl, TerminalControl::CursorPositionEventArgs); TYPED_EVENT(CurrentFontInfo, TerminalControl::TSFInputControl, TerminalControl::FontInfoEventArgs); DECLARE_EVENT(CompositionCompleted, _compositionCompletedHandlers, TerminalControl::CompositionCompletedEventArgs); private: - friend struct TSFInputControlT; - void _layoutRequestedHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextLayoutRequestedEventArgs const& args); void _compositionStartedHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextCompositionStartedEventArgs const& args); void _compositionCompletedHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextCompositionCompletedEventArgs const& args); @@ -58,7 +55,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation void _selectionUpdatingHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextSelectionUpdatingEventArgs const& args); void _textUpdatingHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextTextUpdatingEventArgs const& args); void _formatUpdatingHandler(winrt::Windows::UI::Text::Core::CoreTextEditContext sender, winrt::Windows::UI::Text::Core::CoreTextFormatUpdatingEventArgs const& args); - void _KeyDownHandler(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e); winrt::Windows::UI::Text::Core::CoreTextEditContext::TextRequested_revoker _textRequestedRevoker; winrt::Windows::UI::Text::Core::CoreTextEditContext::SelectionRequested_revoker _selectionRequestedRevoker; @@ -75,8 +71,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation std::wstring _inputBuffer; bool _inComposition; - void _SendAndClearText(); size_t _activeTextStart; + void _SendAndClearText(); }; } namespace winrt::Microsoft::Terminal::TerminalControl::factory_implementation diff --git a/src/cascadia/TerminalControl/TSFInputControl.idl b/src/cascadia/TerminalControl/TSFInputControl.idl index d97ebcf20ba..0722f6d5a0b 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.idl +++ b/src/cascadia/TerminalControl/TSFInputControl.idl @@ -27,6 +27,7 @@ namespace Microsoft.Terminal.TerminalControl void NotifyFocusEnter(); void NotifyFocusLeave(); + void ClearBuffer(); void Close(); } diff --git a/src/cascadia/TerminalControl/TSFInputControl.xaml b/src/cascadia/TerminalControl/TSFInputControl.xaml index 0d742ea30b7..50c87a6e538 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.xaml +++ b/src/cascadia/TerminalControl/TSFInputControl.xaml @@ -6,8 +6,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="768" - d:DesignWidth="1024" - KeyDown="_KeyDownHandler"> + d:DesignWidth="1024"> Date: Tue, 3 Mar 2020 15:21:00 -0800 Subject: [PATCH 6/9] cleanup --- src/cascadia/TerminalControl/TSFInputControl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index 21aa2dca6e3..9094556c3f6 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -310,7 +310,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation else { Canvas().Visibility(Visibility::Visible); - TextBlock().Text(_inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1)); + const auto text = _inputBuffer.substr(range.StartCaretPosition, range.EndCaretPosition - range.StartCaretPosition + 1); + TextBlock().Text(text); } // Notify the TSF that the update succeeded From 8acc8243e66bdcbee976e9604a891fa6d1b9cc67 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 3 Mar 2020 15:53:45 -0800 Subject: [PATCH 7/9] removing unnecessary _activeTextStart setting --- src/cascadia/TerminalControl/TSFInputControl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index 9094556c3f6..ef9e3eb777d 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -304,7 +304,6 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // They aren't composition, so we don't want to wait for the user to start and finish a composition to send the text. if (!_inComposition) { - _activeTextStart = range.StartCaretPosition; _SendAndClearText(); } else From 89354d7491b9be2210759da90e4d5598ce068aec Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Tue, 3 Mar 2020 16:26:32 -0800 Subject: [PATCH 8/9] only clear the buffer if there's something to clear --- .../TerminalControl/TSFInputControl.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index ef9e3eb777d..f3ed69cf26b 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -102,13 +102,16 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // - void TSFInputControl::ClearBuffer() { - TextBlock().Text(L""); - _inputBuffer.clear(); - _editContext.NotifyFocusLeave(); - _editContext.NotifyTextChanged({ 0, ::base::ClampedNumeric(_inputBuffer.length()) }, 0, { 0, 0 }); - _editContext.NotifyFocusEnter(); - _activeTextStart = 0; - _inComposition = false; + if (!_inputBuffer.empty()) + { + TextBlock().Text(L""); + _inputBuffer.clear(); + _editContext.NotifyFocusLeave(); + _editContext.NotifyTextChanged({ 0, ::base::ClampedNumeric(_inputBuffer.length()) }, 0, { 0, 0 }); + _editContext.NotifyFocusEnter(); + _activeTextStart = 0; + _inComposition = false; + } } // Method Description: From 2a40983b559d812049d4e81a00fbe75d0fa06503 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Wed, 4 Mar 2020 11:14:51 -0800 Subject: [PATCH 9/9] saving buf len before i clear it hehe, and changing a var name so i don't get confused and doubt myself --- src/cascadia/TerminalControl/TSFInputControl.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalControl/TSFInputControl.cpp b/src/cascadia/TerminalControl/TSFInputControl.cpp index f3ed69cf26b..0d8a868648d 100644 --- a/src/cascadia/TerminalControl/TSFInputControl.cpp +++ b/src/cascadia/TerminalControl/TSFInputControl.cpp @@ -105,9 +105,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation if (!_inputBuffer.empty()) { TextBlock().Text(L""); + const auto bufLen = ::base::ClampedNumeric(_inputBuffer.length()); _inputBuffer.clear(); _editContext.NotifyFocusLeave(); - _editContext.NotifyTextChanged({ 0, ::base::ClampedNumeric(_inputBuffer.length()) }, 0, { 0, 0 }); + _editContext.NotifyTextChanged({ 0, bufLen }, 0, { 0, 0 }); _editContext.NotifyFocusEnter(); _activeTextStart = 0; _inComposition = false; @@ -293,7 +294,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation // - void TSFInputControl::_textUpdatingHandler(CoreTextEditContext sender, CoreTextTextUpdatingEventArgs const& args) { - const auto text = args.Text(); + const auto incomingText = args.Text(); const auto range = args.Range(); try @@ -301,7 +302,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation _inputBuffer = _inputBuffer.replace( range.StartCaretPosition, ::base::ClampSub(range.EndCaretPosition, range.StartCaretPosition), - text); + incomingText); // If we receive tabbed IME input like emoji, kaomojis, and symbols, send it to the terminal immediately. // They aren't composition, so we don't want to wait for the user to start and finish a composition to send the text.