From 5af87811928df68720643d0bd50f3a1f50921c53 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Mon, 29 Apr 2024 11:53:25 -0700 Subject: [PATCH] Always update ClientPreedit The submode update hack actually doesn't clear client preedit on key release. If we don't reset it to empty, it may be kept. Fix #82 #83 Closes #100 --- src/rimeengine.cpp | 3 ++- src/rimestate.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/rimeengine.cpp b/src/rimeengine.cpp index b0a47cc..18445fa 100644 --- a/src/rimeengine.cpp +++ b/src/rimeengine.cpp @@ -723,7 +723,8 @@ RimeState *RimeEngine::state(InputContext *ic) { return ic->propertyFor(&factory_); } -std::string RimeEngine::subMode(const InputMethodEntry & /*entry*/, InputContext &ic) { +std::string RimeEngine::subMode(const InputMethodEntry & /*entry*/, + InputContext &ic) { if (auto *rimeState = state(&ic)) { return rimeState->subMode(); } diff --git a/src/rimestate.cpp b/src/rimestate.cpp index 8fddcf0..79fb4d3 100644 --- a/src/rimestate.cpp +++ b/src/rimestate.cpp @@ -286,11 +286,12 @@ void RimeState::updatePreedit(InputContext *ic, const RimeContext &context) { case PreeditMode::No: ic->inputPanel().setPreedit(preeditFromRimeContext( context, TextFormatFlag::NoFlag, TextFormatFlag::NoFlag)); + ic->inputPanel().setClientPreedit(Text()); break; case PreeditMode::CommitPreview: { ic->inputPanel().setPreedit(preeditFromRimeContext( context, TextFormatFlag::NoFlag, TextFormatFlag::NoFlag)); - if (context.commit_text_preview) { + if (context.composition.length > 0 && context.commit_text_preview) { Text clientPreedit; clientPreedit.append(context.commit_text_preview, TextFormatFlag::Underline); @@ -300,6 +301,8 @@ void RimeState::updatePreedit(InputContext *ic, const RimeContext &context) { clientPreedit.setCursor(clientPreedit.textLength()); } ic->inputPanel().setClientPreedit(clientPreedit); + } else { + ic->inputPanel().setClientPreedit(Text()); } } break; case PreeditMode::ComposingText: { @@ -381,7 +384,7 @@ void RimeState::commitPreedit(InputContext *ic) { if (!api->get_context(session, &context)) { return; } - if (context.commit_text_preview) { + if (context.composition.length > 0 && context.commit_text_preview) { ic->commitString(context.commit_text_preview); } api->free_context(&context);