emoji: repair one-shot candidate selection

This commit is contained in:
2026-08-11 23:30:41 +09:00
parent 0fff17c8b8
commit 2ae87a3926
14 changed files with 473 additions and 54 deletions

View File

@@ -53,6 +53,7 @@ setkouho(Dictres *res)
static void
show(void)
{
static Drawcmd old;
Drawcmd dc;
Str *pre;
int i, first, n;
@@ -73,7 +74,10 @@ show(void)
if(dc.pre.n == 0 && n == 0 && !visible)
return;
visible = dc.pre.n != 0 || n != 0;
chansend(drawc, &dc);
/* imthread is the sole producer; keep only the newest pending draw. */
while(channbrecv(drawc, &old) > 0)
;
channbsend(drawc, &dc);
}
static void
@@ -227,11 +231,19 @@ transmap(Im *im, Rune c)
static Rune
ctrlkey(Rune c)
{
if(c >= 'A' && c <= 'Z')
c += 'a' - 'A';
if(c >= 'a' && c <= 'z')
return c - 'a' + 1;
return c;
}
static int
ismodkey(u32int ks)
{
return ks >= Kmodfirst && ks <= Kmodlast;
}
static void
foldascii(Str *s)
{
@@ -369,8 +381,8 @@ searchkey(u32int ks, u32int mod, Str *com)
int n, off;
Rune c;
if(ks == Ksuper || ks == Kshift)
return 1;
if(ismodkey(ks))
return 0;
if(ks == Kdown || ks == Kup){
if(im.nkouho == 0)
return 1;
@@ -383,7 +395,7 @@ searchkey(u32int ks, u32int mod, Str *com)
}
n = ks - '1';
off = im.sel >= Maxdisp ? im.sel - Maxdisp + 1 : 0;
if((mod & Malt) && n >= 0 && n < Maxdisp){
if(n >= 0 && n < Maxdisp && off + n < im.nkouho && mod == 0){
pickemoji(off + n, com);
return 1;
}
@@ -454,8 +466,8 @@ keystroke(u32int ks, u32int mod, Str *com)
int n, off;
Rune c;
if(ks == Ksuper || ks == Kshift)
return 1;
if(ismodkey(ks))
return 0;
if(search.on)
return searchkey(ks, mod, com);
if(ks == Kdown || ks == Kup){
@@ -568,6 +580,16 @@ imhandlekey(Keyreq *kr)
chansend(kr->reply, &res);
}
static void
dictresult(Dictres *res)
{
if(search.on || res->lang != im.l->lang ||
scmp(&res->key, &im.pre) != 0)
return;
setkouho(res);
show();
}
void
imthread(void*)
{
@@ -587,11 +609,7 @@ imthread(void*)
imhandlekey(&kr);
break;
case 1:
if(!search.on && res.lang == im.l->lang &&
scmp(&res.key, &im.pre) == 0){
setkouho(&res);
show();
}
dictresult(&res);
break;
}
}