From 044e53198a3cf5f0af20267f3ad180bb82b96fb4 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Thu, 18 Mar 2021 17:29:07 +0100 Subject: [PATCH] fix(linux): Fix switching to keyboard in middle of line (#4678) Don't re-set context if it changed because the cursor location was wrong. When the user switches to the EuroLatin keyboard in the middle of the line, we're getting a wrong cursor location. This will be fixed with the next keypress, but it leads to the context string suddenly having more characters added to the front. If we re-set the context because it's different now we will loose the information we previously added to the context. We now compare the end of the string. If the new context string ends with the old context string we assume that the cursor position got updated and don't re-set the context. This fixes #4678. --- common/core/desktop/tests/unit/kmx/kmx.cpp | 2 -- linux/ibus-keyman/src/engine.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/common/core/desktop/tests/unit/kmx/kmx.cpp b/common/core/desktop/tests/unit/kmx/kmx.cpp index bcb047f8d1..2f4ec39945 100644 --- a/common/core/desktop/tests/unit/kmx/kmx.cpp +++ b/common/core/desktop/tests/unit/kmx/kmx.cpp @@ -364,8 +364,6 @@ int run_test(const km::kbp::path & source, const km::kbp::path & compiled) { } std::string string_to_hex(const std::u16string& input) { - static const char hex_digits[] = "0123456789ABCDEF"; - std::ostringstream result; result << std::setfill('0') << std::hex << std::uppercase; diff --git a/linux/ibus-keyman/src/engine.c b/linux/ibus-keyman/src/engine.c index 080c3edbd9..e3f0dfd2b7 100644 --- a/linux/ibus-keyman/src/engine.c +++ b/linux/ibus-keyman/src/engine.c @@ -220,7 +220,7 @@ static void reset_context(IBusEngine *engine) g_message("new context is:%u:%s: cursor:%d anchor:%d", context_pos - context_start, surrounding_text, cursor_pos, anchor_pos); g_message(":%s:%s:", surrounding_text, current_context_utf8); - if (g_strcmp0(surrounding_text, current_context_utf8) != 0) + if (!g_str_has_suffix(surrounding_text, current_context_utf8)) { g_message("setting context because it has changed from expected"); if (km_kbp_context_items_from_utf8(surrounding_text, &context_items) == KM_KBP_STATUS_OK) {