engine: a romaji typo stays in the reading

A key that could not go on with the pending romaji, when that was not a
syllable either, committed the whole reading to the application and
passed the key on: one slip dumped かんj into the text with no way back.
The letters typed now stay in the reading as they are, like any other
IME shows them, and Backspace mends them; only a key that starts no
syllable at all still ends the composition.
This commit is contained in:
2026-08-17 01:17:12 +09:00
parent 95dff0b82b
commit f61f7ab5f8
2 changed files with 28 additions and 11 deletions

View File

@@ -327,20 +327,21 @@ transjp(Im *p, Rune c)
} }
return e; return e;
} }
if(e.raw.n != 0 && mapget(p->l->map, &e.raw, &mapped)){ /* The pending romaji is done: kana if it is complete, else the
sappend(&e.next, &mapped); * letters as typed, for Backspace to mend. */
sclear(&e.raw); if(!mapget(p->l->map, &e.raw, &mapped))
sclear(&key); mapped = e.raw;
sputr(&key, c); sappend(&e.next, &mapped);
if(mapmatch(p->l->map, &key, &mapped) != TrieMiss){ sclear(&e.raw);
e.raw = key; sclear(&key);
return e; 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. */ /* 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.next);
sclear(&e.raw);
e.eat = 0; e.eat = 0;
return e; return e;
} }

View File

@@ -1184,6 +1184,22 @@ engine_japanese_candidates(struct ct *t)
checkstr(t, "language switch takes the candidate", "漢字", &com); checkstr(t, "language switch takes the candidate", "漢字", &com);
CT_EQ_INT(t, LangKO, im.l->lang); CT_EQ_INT(t, LangKO, im.l->lang);
im.l = jp; 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. */ /* Backspace looks a complete shorter reading up again. */
setdict(jp->dict, "かん", ""); setdict(jp->dict, "かん", "");
if(!typekeys(t, "kanji", &com)) if(!typekeys(t, "kanji", &com))