From a844bbbe7b818cd6eae3ab6128fc3d3ffb891060 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Tue, 3 Dec 2019 15:48:44 +0800 Subject: [PATCH] improve input engine fix issue #290 --- docs/changes.md | 1 + src/base/input_engine.c | 8 ++++---- src/base/input_engine.h | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 8e0075ad0..847a748a7 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -6,6 +6,7 @@ * idle\_manager\_exist 判断条件有误(感谢朝泽提供补丁)。 * 完善 widget\_create\_animator(感谢培煌提供补丁)。 * 在窗口打开时递归update style。 + * 完善输入避免google pinyin崩溃 * 2019/12/02 * 完整 list item 支持 return/space 激活 (感谢 [jianmin zhuang](https://github.com/zjm1060) 提供补丁)。 diff --git a/src/base/input_engine.c b/src/base/input_engine.c index 2568aa634..58e4230ac 100644 --- a/src/base/input_engine.c +++ b/src/base/input_engine.c @@ -40,10 +40,6 @@ ret_t input_engine_input(input_engine_t* engine, int key) { ret_t ret = RET_OK; return_value_if_fail(engine != NULL, RET_BAD_PARAMS); - if (engine->keys.size >= TK_IM_MAX_INPUT_CHARS) { - return RET_BAD_PARAMS; - } - if (key == TK_KEY_BACKSPACE || key == TK_KEY_DELETE) { if (engine->keys.size > 0) { engine->keys.size--; @@ -52,6 +48,10 @@ ret_t input_engine_input(input_engine_t* engine, int key) { return RET_FAIL; } } else { + if (engine->keys.size >= TK_IM_MAX_INPUT_CHARS) { + return RET_BAD_PARAMS; + } + str_append_char(&(engine->keys), (char)key); } diff --git a/src/base/input_engine.h b/src/base/input_engine.h index a2e3eec9a..9549a66c4 100644 --- a/src/base/input_engine.h +++ b/src/base/input_engine.h @@ -32,7 +32,7 @@ typedef struct _input_engine_t input_engine_t; typedef ret_t (*input_engine_reset_input_t)(input_engine_t* engine); typedef ret_t (*input_engine_input_t)(input_engine_t* engine, int key); -#define TK_IM_MAX_INPUT_CHARS 15 +#define TK_IM_MAX_INPUT_CHARS 11 #define TK_IM_MAX_CANDIDATE_CHARS 127 /**