Permalink
Browse files

Merge pull request #274 from hiunnhue/fix_space

Fix: chewing_handle_Space() cannot input space when buffer is empty
  • Loading branch information...
2 parents 5d02863 + 8b7e4c3 commit 7282e054ad87023ef5991f292709f84c396bbdba @jserv jserv committed Aug 9, 2017
Showing with 23 additions and 6 deletions.
  1. +5 −6 src/chewingio.c
  2. +18 −0 test/test-bopomofo.c
View
@@ -835,13 +835,13 @@ CHEWING_API int chewing_handle_Space(ChewingContext *ctx)
* - "space as selection" mode is disable
* - mode is not CHINESE_MODE
* - has incompleted bopomofo (space is needed to complete it)
+ * - pre-edit buffer is empty
*/
- if (!pgdata->config.bSpaceAsSelection || pgdata->bChiSym != CHINESE_MODE || BopomofoIsEntering(&ctx->data->bopomofoData)) {
+ if (!pgdata->config.bSpaceAsSelection || pgdata->bChiSym != CHINESE_MODE ||
+ BopomofoIsEntering(&ctx->data->bopomofoData) || pgdata->chiSymbolBufLen == 0) {
return chewing_handle_Default(ctx, ' ');
}
- CheckAndResetRange(pgdata);
-
/*
* space = right when the follogin conditions are true
* 1. In select mode
@@ -851,10 +851,9 @@ CHEWING_API int chewing_handle_Space(ChewingContext *ctx)
*/
if (pgdata->bSelect && ctx->output->pci->pageNo < ctx->output->pci->nPage - 1) {
return chewing_handle_Right(ctx);
- } else {
- return chewing_handle_Down(ctx);
}
- return 0;
+
+ return chewing_handle_Down(ctx);
}
CHEWING_API int chewing_handle_Esc(ChewingContext *ctx)
View
@@ -1134,6 +1134,23 @@ void test_Numlock()
test_Numlock_select_candidate();
}
+void test_Space_empty_buffer()
+{
+ ChewingContext *ctx;
+
+ clean_userphrase();
+
+ ctx = chewing_new();
+ start_testcase(ctx, fd);
+ chewing_set_spaceAsSelection(ctx, 1);
+
+ type_keystroke_by_string(ctx, " ");
+ ok_preedit_buffer(ctx, "");
+ ok_commit_buffer(ctx, " ");
+
+ chewing_delete(ctx);
+}
+
void test_Space_selection_word()
{
ChewingContext *ctx;
@@ -1205,6 +1222,7 @@ void test_Space_selection_symbol()
void test_Space()
{
+ test_Space_empty_buffer();
test_Space_selection_word();
test_Space_selection_symbol();
}

0 comments on commit 7282e05

Please sign in to comment.