From 49e4eea60f737b46b8aeda505f4693df8a9d44a6 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Wed, 8 May 2024 22:58:19 +0200 Subject: [PATCH] Fix typing multiple emojis on Windows 10 (#17213) On Windows 10 Emojis don't finish composition until the Emoji picker panel is closed. Each emoji is thus its own composition range. `firstRange` thus caused only the first emoji to finish composition. The end result was that all remaining emojis would stay around forever, with the user entirely unable to clear them. ## Validation Steps Performed * Windows 10 VM * Open Emoji picker (Win+.) * Press and hold Enter on any Emoji * Press Esc to finish the composition * All of the Emoji can be backspaced / deleted --- src/tsf/Implementation.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/tsf/Implementation.cpp b/src/tsf/Implementation.cpp index d3ad65ae9c..aa7ace81fc 100644 --- a/src/tsf/Implementation.cpp +++ b/src/tsf/Implementation.cpp @@ -436,7 +436,7 @@ void Implementation::_doCompositionUpdate(TfEditCookie ec) std::wstring finalizedString; std::wstring activeComposition; til::small_vector activeCompositionRanges; - bool firstRange = true; + bool activeCompositionEncountered = false; const GUID* guids[] = { &GUID_PROP_COMPOSING, &GUID_PROP_ATTRIBUTE }; wil::com_ptr props; @@ -500,7 +500,9 @@ void Implementation::_doCompositionUpdate(TfEditCookie ec) ULONG len = bufCap; THROW_IF_FAILED(range->GetText(ec, TF_TF_MOVESTART, buf, len, &len)); - if (!composing && firstRange) + // Since we can't un-finalize finalized text, we only finalize text that's at the start of the document. + // In other words, don't put text that's in the middle between two active compositions into the finalized string. + if (!composing && !activeCompositionEncountered) { finalizedString.append(buf, len); } @@ -520,7 +522,7 @@ void Implementation::_doCompositionUpdate(TfEditCookie ec) const auto attr = _textAttributeFromAtom(atom); activeCompositionRanges.emplace_back(totalLen, attr); - firstRange = false; + activeCompositionEncountered |= composing; } }