diff --git a/strans.c b/strans.c index 1e77344..8234c57 100644 --- a/strans.c +++ b/strans.c @@ -327,20 +327,21 @@ transjp(Im *p, Rune c) } return e; } - if(e.raw.n != 0 && mapget(p->l->map, &e.raw, &mapped)){ - sappend(&e.next, &mapped); - sclear(&e.raw); - sclear(&key); - sputr(&key, c); - if(mapmatch(p->l->map, &key, &mapped) != TrieMiss){ - e.raw = key; - return e; - } + /* The pending romaji is done: kana if it is complete, else the + * letters as typed, for Backspace to mend. */ + if(!mapget(p->l->map, &e.raw, &mapped)) + mapped = e.raw; + sappend(&e.next, &mapped); + sclear(&e.raw); + sclear(&key); + sputr(&key, c); + if(mapmatch(p->l->map, &key, &mapped) != TrieMiss){ + e.raw = key; + return e; } /* The key starts no syllable: flush the reading and pass it on. */ - jpreading(p->l->map, &e.next, &e.raw, &e.s); + e.s = e.next; sclear(&e.next); - sclear(&e.raw); e.eat = 0; return e; } diff --git a/tests/engine_test.c b/tests/engine_test.c index 5acb091..ee54571 100644 --- a/tests/engine_test.c +++ b/tests/engine_test.c @@ -1184,6 +1184,22 @@ engine_japanese_candidates(struct ct *t) checkstr(t, "language switch takes the candidate", "漢字", &com); CT_EQ_INT(t, LangKO, im.l->lang); im.l = jp; + /* A romaji typo stays in the reading for Backspace to mend. */ + sclear(&com); + if(!typekeys(t, "kanjr", &com)) + goto cleanup; + impre(&im, &shown); + checkstr(t, "typo kept", "かんjr", &shown); + CT_CHECK(t, keystroke(Kback, 0, &com)); + impre(&im, &shown); + checkstr(t, "typo half mended", "かんj", &shown); + CT_CHECK(t, keystroke(Kback, 0, &com)); + if(!typekeys(t, "ji", &com)) + goto cleanup; + impre(&im, &shown); + checkstr(t, "typo mended", "かんじ", &shown); + CT_EQ_INT(t, 2, im.nkouho); + CT_CHECK(t, keystroke(Kesc, 0, &com)); /* Backspace looks a complete shorter reading up again. */ setdict(jp->dict, "かん", "缶"); if(!typekeys(t, "kanji", &com))