From 97e6f2cf1ac4bf9548c929668231ddbb1434fec7 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Mon, 17 Aug 2026 01:24:56 +0900 Subject: [PATCH] engine: one ASCII fold, commitim through impre, no second modifier check Four places lower-cased ASCII by hand; commitim repeated impre's three lines to compute the text it commits; and transition() began by rejecting modifier keys that imhandlekey's keymeaningful() had already turned away, kept alive only by tests calling transition() directly. The test helper now goes through the same gate. --- strans.c | 28 +++++++++++++++------------- tests/engine_test.c | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/strans.c b/strans.c index da1c7ad..9d71532 100644 --- a/strans.c +++ b/strans.c @@ -347,10 +347,7 @@ commitim(Im *p, Str *com) { Str val; - if(isjp(p)) - jpreading(p->l->map, &p->pre, &p->raw, &val); - else if(!mapget(p->l->map, &p->pre, &val)) - val = p->pre; + impre(p, &val); sappend(com, &val); sclear(&p->pre); sclear(&p->raw); @@ -483,21 +480,29 @@ transmap(Im *p, Rune c) return e; } +/* ASCII only: what the maps and dictionaries fold too. */ static Rune -ctrlkey(Rune c) +lower(Rune c) { if(c >= 'A' && c <= 'Z') c += 'a' - 'A'; + return c; +} + +static Rune +ctrlkey(Rune c) +{ + c = lower(c); if(c >= 'a' && c <= 'z') return c - 'a' + 1; return c; } +/* Caps Lock does not shift a Korean key; Shift does. */ static Rune kokey(Rune c, u32int mod) { - if(c >= 'A' && c <= 'Z') - c += 'a' - 'A'; + c = lower(c); if((mod & Mshift) && c >= 'a' && c <= 'z') c -= 'a' - 'A'; return c; @@ -522,8 +527,7 @@ foldascii(Str *s) int i; for(i = 0; i < s->n; i++) - if(s->r[i] >= 'A' && s->r[i] <= 'Z') - s->r[i] += 'a' - 'A'; + s->r[i] = lower(s->r[i]); } /* @@ -748,12 +752,10 @@ transition(u32int ks, u32int mod, Str *com) int n; Rune c; - if(ismodkey(ks)) - return 0; if(im.l->lang == LangKO) ks = kokey(ks, mod); - else if(isjp(&im) && ks >= 'A' && ks <= 'Z') - ks += 'a' - 'A'; /* romaji is case-blind, Caps Lock included */ + else if(isjp(&im)) + ks = lower(ks); /* romaji is case-blind, Caps Lock included */ /* The Korean keyboard's 한/영 and 한자 keys are Ctrl+S or Ctrl+T, and Ctrl+H. */ if(ks == Khangul){ ks = im.l->lang == LangKO ? 't' : 's'; diff --git a/tests/engine_test.c b/tests/engine_test.c index 032d006..bb5675b 100644 --- a/tests/engine_test.c +++ b/tests/engine_test.c @@ -10,7 +10,7 @@ keystroke(u32int ks, u32int mod, Str *com) { int eaten; - eaten = transition(ks, mod, com); + eaten = keymeaningful(ks) && transition(ks, mod, com); redraw(); return eaten; }