fix(frontends): restart preedit around commits

This commit is contained in:
2026-08-15 15:42:35 +09:00
parent 67ed2ef478
commit a1ef8a4744
5 changed files with 136 additions and 30 deletions

View File

@@ -21,8 +21,23 @@ struct Log
int transfer;
int atext;
int aclear;
char revent[16];
int rn;
int repeat;
int rfirst;
int rcommit;
int rdone;
};
static void
revent(Log *log, char c)
{
if(log->rn + 1 < (int)sizeof log->revent){
log->revent[log->rn++] = c;
log->revent[log->rn] = '\0';
}
}
static void
legacy(IBusInputContext *ctx, IBusText *text, guint cursor,
gboolean visible, void *arg)
@@ -36,6 +51,28 @@ legacy(IBusInputContext *ctx, IBusText *text, guint cursor,
log = arg;
log->legacy++;
s = ibus_text_get_text(text);
if(log->repeat != 0){
revent(log, 'P');
if(log->repeat == 1){
if(s[0] == '\0'){
if(cursor != 0 || visible)
log->invalid = 1;
}else if(strcmp(s, "") != 0 || cursor != 1 || !visible)
log->invalid = 1;
else
log->rfirst = 1;
}else if(s[0] == '\0'){
if(cursor != 0 || visible || log->rcommit)
log->invalid = 1;
}else if(strcmp(s, "") != 0 || cursor != 1 || !visible ||
!log->rcommit)
log->invalid = 1;
else
log->rdone = 1;
if(log->loop != NULL && log->waiting != NULL && *log->waiting)
g_main_loop_quit(log->loop);
return;
}
if(strcmp(s, "k") == 0){
attrs = ibus_text_get_attributes(text);
a = attrs == NULL ? NULL : ibus_attr_list_get(attrs, 0);
@@ -97,6 +134,17 @@ commit(IBusInputContext *ctx, IBusText *text, void *arg)
log->commit++;
s = ibus_text_get_text(text);
attrs = ibus_text_get_attributes(text);
if(log->repeat != 0){
revent(log, 'K');
if(log->repeat != 2 || strcmp(s, "") != 0 || attrs == NULL ||
ibus_attr_list_get(attrs, 0) != NULL)
log->invalid = 1;
else
log->rcommit = 1;
if(log->loop != NULL && log->waiting != NULL && *log->waiting)
g_main_loop_quit(log->loop);
return;
}
if(strcmp(s, "") != 0 || attrs == NULL ||
ibus_attr_list_get(attrs, 0) != NULL)
log->invalid = 1;
@@ -194,10 +242,22 @@ main(int argc, char **argv)
waitflag(&log, &log.aclear);
ibus_input_context_focus_out(b);
}
ibus_input_context_focus_in(a);
ok = ok && ibus_input_context_process_key_event(a, 's', 0,
IBUS_CONTROL_MASK);
log.repeat = 1;
ok = ok && ibus_input_context_process_key_event(a, 'z', 0, 0) &&
waitflag(&log, &log.rfirst);
log.repeat = 2;
log.revent[0] = '\0';
log.rn = 0;
ok = ok && ibus_input_context_process_key_event(a, 'z', 0, 0) &&
waitflag(&log, &log.rdone) && strcmp(log.revent, "PKP") == 0;
log.repeat = 0;
ibus_input_context_focus_out(a);
if(log.legacy == 0 || log.modern != 0 || log.commit != 1 ||
if(log.legacy == 0 || log.modern != 0 || log.commit != 2 ||
log.invalid || !log.done || !log.atext || !log.aclear ||
log.clearctx != a)
log.clearctx != a || !log.rdone)
ok = 0;
if(b != NULL)
g_object_unref(b);
@@ -205,9 +265,10 @@ main(int argc, char **argv)
g_object_unref(bus);
if(!ok){
fprintf(stderr,
"ibus_client_smoke: legacy=%d modern=%d commit=%d invalid=%d preedit=%d committed=%d transfer-text=%d a-clear=%d\n",
"ibus_client_smoke: legacy=%d modern=%d commit=%d invalid=%d preedit=%d committed=%d transfer-text=%d a-clear=%d repeat=%s\n",
log.legacy, log.modern, log.commit, log.invalid,
log.sawpreedit, log.sawcommit, log.atext, log.aclear);
log.sawpreedit, log.sawcommit, log.atext, log.aclear,
log.revent);
return 1;
}
printf("official libibus client preedit, commit, and owner clear: ok\n");