Skip to content

Commit

Permalink
Merge pull request #260 from hiunnhue/fix_206
Browse files Browse the repository at this point in the history
Auto learn phrases only after committing
  • Loading branch information
jserv committed May 15, 2017
2 parents 6bffc95 + 7e3569c commit cad4a6e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
12 changes: 0 additions & 12 deletions src/choice.c
Expand Up @@ -530,24 +530,12 @@ int ChoiceEndChoice(ChewingData *pgdata)
return 0;
}

static void ChangeUserData(ChewingData *pgdata, int selectNo)
{
uint16_t userPhoneSeq[MAX_PHONE_SEQ_LEN];
int len;

len = ueStrLen(pgdata->choiceInfo.totalChoiceStr[selectNo]);
memcpy(userPhoneSeq, &(pgdata->phoneSeq[PhoneSeqCursor(pgdata)]), len * sizeof(uint16_t));
userPhoneSeq[len] = 0;
UserUpdatePhrase(pgdata, userPhoneSeq, pgdata->choiceInfo.totalChoiceStr[selectNo]);
}

/** @brief commit the selected phrase. */
int ChoiceSelect(ChewingData *pgdata, int selectNo)
{
ChoiceInfo *pci = &(pgdata->choiceInfo);
AvailInfo *pai = &(pgdata->availInfo);

ChangeUserData(pgdata, selectNo);
ChangeSelectIntervalAndBreakpoint(pgdata,
PhoneSeqCursor(pgdata),
PhoneSeqCursor(pgdata) + pai->avail[pai->currentAvail].len,
Expand Down
37 changes: 35 additions & 2 deletions test/test-userphrase.c
Expand Up @@ -239,12 +239,12 @@ void test_userphrase_auto_learn()
ctx = chewing_new();
start_testcase(ctx, fd);

ok(has_userphrase(ctx, bopomofo_1, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_2);
ok(has_userphrase(ctx, bopomofo_1, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_1);
ok(has_userphrase(ctx, bopomofo_2, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_2);

type_keystroke_by_string(ctx, "dk dk dk hk4g4<E>");

ok(has_userphrase(ctx, bopomofo_1, NULL) == 1, "`%s' shall be in userphrase", bopomofo_2);
ok(has_userphrase(ctx, bopomofo_1, NULL) == 1, "`%s' shall be in userphrase", bopomofo_1);
ok(has_userphrase(ctx, bopomofo_2, NULL) == 1, "`%s' shall be in userphrase", bopomofo_2);

chewing_delete(ctx);
Expand Down Expand Up @@ -303,11 +303,44 @@ void test_userphrase_auto_learn_hardcode_break()
chewing_delete(ctx);
}

void test_userphrase_auto_learn_only_after_commit()
{
/* GitHub #206: It should add the word after user actually finish the character selection. */

const char bopomofo_1[] = "\xE3\x84\x94\xE3\x84\xA4\xCB\x8A \xE3\x84\x86\xE3\x84\xA2\xCB\x8A"; /* ㄔㄤˊ ㄆㄢˊ */
const char bopomofo_2[] = "\xE3\x84\x94\xE3\x84\xA4\xCB\x8A"; /* ㄔㄤˊ */

ChewingContext *ctx;

clean_userphrase();

ctx = chewing_new();
start_testcase(ctx, fd);

/* user just inputs some characters: don't auto learn. */
type_keystroke_by_string(ctx, "t;6q06");
ok(has_userphrase(ctx, bopomofo_1, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_1);
ok(has_userphrase(ctx, bopomofo_2, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_2);

/* user selectes a candidate on the list, but doesn't commit: don't auto learn. */
type_keystroke_by_string(ctx, "<L><L><D>7");
ok(has_userphrase(ctx, bopomofo_1, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_1);
ok(has_userphrase(ctx, bopomofo_2, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_2);

/* user selectes another cadidate and commit: auto learn phrase(s), but not the selected candidate. */
type_keystroke_by_string(ctx, "<L><D>2<E>");
ok(has_userphrase(ctx, bopomofo_1, NULL) == 1, "`%s' shall be in userphrase", bopomofo_1);
ok(has_userphrase(ctx, bopomofo_2, NULL) == 0, "`%s' shall not be in userphrase", bopomofo_2);

chewing_delete(ctx);
}

void test_userphrase()
{
test_userphrase_auto_learn();
test_userphrase_auto_learn_with_symbol();
test_userphrase_auto_learn_hardcode_break();
test_userphrase_auto_learn_only_after_commit();
}

void test_userphrase_enumerate_normal()
Expand Down

1 comment on commit cad4a6e

@ottokang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這個功能當初這樣設計,是不是要提昇選字優先出現的順位?

Please sign in to comment.