fix(sdk/ime): IME 修复(shift小写基/OK只提交不关/阻塞喂on_tick agent-169) + dialog INPUT回归(dlg_ime_change_cb实时回写+适配新语义 agent-173) + test_sdk_fixes shift断言更新 + 宿主测试test_ime_fix

This commit is contained in:
MeowOS committed 2026-08-31 02:01:56 +08:00
1 parent c515a33ac4
commit 2d7fe81229
7 files changed
+359 -15

No files matched your search

+36
View File
@@ -64,6 +64,7 @@ struct meow_dialog {
int done;
meow_ime_ctx ime; /* INPUT 型(拷贝) */
int has_ime;
meow_ime_ctx *ime_orig; /* INPUT:App 传入的原始 ctx(回写最终文本,App 关闭后可读回) */
};
/* 卡片几何:返回标题之后内容起点(行/按钮相对坐标)。 */
@@ -162,6 +163,30 @@ static void dlg_repaint(meow_dialog *d, const meow_theme *th)
meow_ui_flush_region(g.dx, g.dy, g.dw, g.dh);
}
/* M2.71-IME-fix:dialog INPUT 的 on_change——实时把 IME 文本回写进 d->ime.buf(dialog 内部拷贝),
* 并重绘卡片预览区,使用户边打字边看到当前文本。ESC/点背景(result=0)关闭后 d->ime.buf 仍是
* 最新文本(否则 meow_ime_close(0) 不回写 buf → 文本丢失)。d->ime.buf 是 dialog 内部缓冲
* (非 App 持有);App 的最终文本经 ime_orig 在关闭时回写(见 OK 按钮处理)。 */
static void dlg_ime_change_cb(const char *text, void *ctx)
{
meow_dialog *d = (meow_dialog *)ctx;
if (!d) return;
if (text) {
strncpy(d->ime.buf, text, sizeof d->ime.buf - 1);
d->ime.buf[sizeof d->ime.buf - 1] = 0;
}
const meow_theme *th = meow_theme_get();
dlg_repaint(d, th);
}
/* 准备好 dialog 的 IME 上下文:无论 App 传入(set_ime)或内部兜底(show 的默认 ctx),
* 都由 dialog 接管 on_change/ctx,以支持 dlg_ime_change_cb 的实时回写。 */
static void dlg_prep_ime(meow_dialog *d)
{
d->ime.on_change = dlg_ime_change_cb;
d->ime.ctx = d;
}
meow_dialog *meow_dialog_create(meow_dlg_t t, const char *title)
{
meow_dialog *d = (meow_dialog *)calloc(1, sizeof *d);
@@ -183,7 +208,9 @@ void meow_dialog_set_ime(meow_dialog *d, meow_ime_ctx *ime)
{
if (!d || !ime) return;
d->ime = *ime;
d->ime_orig = ime; /* M2.71-IME-fix:记住 App 原始 ctx,关闭时回写最终文本 */
d->has_ime = 1;
dlg_prep_ime(d); /* dialog 接管 on_change:实时回写 d->ime.buf + 重绘卡片 */
}
void meow_dialog_close(meow_dialog *d)
@@ -199,6 +226,8 @@ void meow_dialog_show(meow_dialog *d)
if (d->type == MEOW_DLG_INPUT && !d->has_ime) {
memset(&d->ime, 0, sizeof d->ime);
d->ime.maxlen = 255;
d->ime_orig = NULL; /* 无 App 原始 ctx,关闭时不回写 */
dlg_prep_ime(d);
}
meow_input_start();
meow_input_drain(); /* 排空残留触摸(goodix 长尾) */
@@ -236,6 +265,13 @@ void meow_dialog_show(meow_dialog *d)
} else if (x >= cx && x < cx + g.btn_w) { /* OK */
if (d->type == MEOW_DLG_INPUT) {
d->result = meow_ui_text_input(&d->ime); /* 阻塞编辑 */
/* M2.71-IME-fix:回车只提交不关(键盘仍开);文本经 on_change 已实时
* 写进 d->ime.buf。这里无论 result=0/1 都把最终文本回写 App 原始 ctx,
* 保证 ESC/点背景(result=0)关闭后 App 仍能读到编辑结果(不再丢失)。 */
if (d->ime_orig) {
strncpy(d->ime_orig->buf, d->ime.buf, sizeof d->ime_orig->buf - 1);
d->ime_orig->buf[sizeof d->ime_orig->buf - 1] = 0;
}
} else {
d->result = (d->type == MEOW_DLG_CONFIRM) ? 1 : 1;
}