From d7a224dcc3ee565f6eeaac5d3275f1784dd34a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Tue, 17 Nov 2026 20:07:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AD=89=E4=BD=A0=E5=85=81=E8=A8=B1?= =?UTF-8?q?=E7=9A=84=E5=8D=A1=E7=89=87=EF=BC=9A=E5=90=8C=E7=B7=A8=E8=99=9F?= =?UTF-8?q?=E7=9A=84=E5=8D=A1=E5=88=86=E5=BE=97=E9=96=8B=E3=80=81=E6=96=B0?= =?UTF-8?q?=E5=8D=A1=E4=B8=80=E5=88=B0=E5=B0=B1=E9=87=8D=E6=96=B0=E7=AD=89?= =?UTF-8?q?=EF=BC=9B=E5=95=8F=E9=A1=8C=E5=8D=A1=E4=B8=8D=E6=90=B6=E6=AD=A3?= =?UTF-8?q?=E5=9C=A8=E6=89=93=E5=AD=97=E7=9A=84=E6=B8=B8=E6=A8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 第十輪審查沒有 P0/P1(也確認 Enter 快捷鍵在實際 App 照常可用:每個 pass 都會畫到卡片)。 照它的 P2 收尾: - 卡片編號會重複(沒給編號的服務每一輪都是 call_0、call_1…):記住的上一幀狀態改成每個 Bot 各一份,卡片用「到達時的隨機鍵+編號+理由」分辨;新卡一到(on_new_approval)就重新計時。 - 沒有選項的問題卡在游標停在別的欄位(例如正在聊天框打字)時不搶游標。 - 測試補上放開按鍵,「很快按第二下」真的是第二下;加上兩個 Bot 同編號的情況。 已驗證: cargo test 整套連跑 5 次全綠(622);a_new_card_or_a_second_enter_is_not_a_yes 的同編號情況 拿掉修正時會失敗。 未驗證: 實機按鍵手感。 動到審批路徑(approval_dock、on_new_approval):依 CLAUDE.md 需要實機測試+人類簽名,不得自行發佈。 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha3KhvSzysuKUobKUTR --- src/app.rs | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/app.rs b/src/app.rs index 476f97f..e92d908 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3990,8 +3990,10 @@ impl App { // What was kept is this card's, from the frame just before (not another bot's card, not // from before the person came back to this chat): otherwise it counts as blocked. let composer = egui::Id::unique(("composer", bot.id)); - let seen = egui::Id::unique("approval-dock-caret"); - let card = self.approvals.get(&bot.id).map(|a| a.call_id.clone()).unwrap_or_default(); + // (Each bot's own; a card is told apart by its arrival key, its call id and its words — + // call ids repeat: a service that gives none gets call_0, call_1… every round.) + let seen = egui::Id::unique(("approval-dock-caret", bot.id)); + let card = self.approvals.get(&bot.id).map(|a| format!("{}|{}|{}", self.ask_keys.get(&bot.id).map(String::as_str).unwrap_or(""), a.call_id, a.reason)).unwrap_or_default(); let pass = ctx.cumulative_pass_nr(); let kept: Option<(Option, bool, u64, String)> = ctx.data(|d| d.get_temp(seen)); let fresh = kept.as_ref().is_some_and(|k| k.2 + 1 == pass && k.3 == card); @@ -4123,7 +4125,10 @@ impl App { // settings are open over it (it took the caret from whatever was being typed there); // it gets it once they close. let dialog_open = self.show_settings || ui.ctx().memory(|m| m.top_modal_layer()).is_some(); - if q.options.is_empty() && !dialog_open && self.ask_focus.as_ref() != Some(&(call_id.clone(), step)) { + // (Nor while the caret is in another field — the chat's input with words being typed: + // they and their Enter would go into the answer.) + let typing_elsewhere = ui.ctx().memory(|m| m.focused()).is_some_and(|f| f != typed_id); + if q.options.is_empty() && !dialog_open && !typing_elsewhere && self.ask_focus.as_ref() != Some(&(call_id.clone(), step)) { self.ask_focus = Some((call_id.clone(), step)); field.request_focus(); } @@ -4315,6 +4320,8 @@ impl App { /// attention (the Dock icon bounces when AnyBot isn't in front, and the 提示音 rings). fn on_new_approval(&mut self, ctx: &egui::Context, bot_id: u64) { self.popup_hidden.remove(&bot_id); + // (A new card waits its own moment before it takes Enter / Esc.) + self.ask_shown.remove(&bot_id); let key = crate::httpd::random_hex(16); self.ask_keys.insert(bot_id, key.clone()); // (A brain on a server has nobody to hear it.) @@ -7994,8 +8001,9 @@ mod tests { app.ask_shown.insert(id, Instant::now() - std::time::Duration::from_secs(2)); frame(&mut app, vec![enter.clone()], false); assert_eq!(steer.lock().unwrap().len(), 1, "the words went"); - // The same Enter held a moment (its repeat), and a quick second one: neither is the yes. + // The same Enter held a moment (its repeat), let go, and a quick second press: neither is the yes. frame(&mut app, vec![egui::Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: true, modifiers: egui::Modifiers::NONE }], false); + frame(&mut app, vec![egui::Event::Key { key: Key::Enter, physical_key: None, pressed: false, repeat: false, modifiers: egui::Modifiers::NONE }], false); frame(&mut app, vec![enter.clone()], false); let r = got.try_recv(); assert!(!matches!(r, Ok(ApprovalAnswer::Once)) && app.approvals.contains_key(&id), "the Enter right after sending isn't a yes"); @@ -8013,8 +8021,25 @@ mod tests { frame2(&mut app2, vec![]); app2.ask_shown.insert(id2, Instant::now() - std::time::Duration::from_secs(2)); let got2 = card(&mut app2, id2, "c2"); - frame2(&mut app2, vec![enter]); + frame2(&mut app2, vec![enter.clone()]); assert!(got2.try_recv().is_err(), "a card seen for no time isn't answered"); + // Two bots, each with a card called 「call_0」 (a service that gives no ids): looking at + // one a while, then back to the other — its first frame doesn't take an Enter. + let (ctx3, mut app3) = setup("anybot-same-call-id.png"); + let (a, b) = (app3.state.bots[0].id, app3.state.bots[1].id); + let (bot_a, bot_b) = (app3.state.bot(a).unwrap().clone(), app3.state.bot(b).unwrap().clone()); + let got_a = card(&mut app3, a, "call_0"); + let _got_b = card(&mut app3, b, "call_0"); + let show = |app: &mut super::App, bot: &crate::model::Bot, events: Vec| { + let mut out = ctx3.run_ui(egui::RawInput { events, ..Default::default() }, |ui| app.composer(ui, &ctx3, bot)); + out.textures_delta.clear(); + }; + show(&mut app3, &bot_a, vec![]); + show(&mut app3, &bot_b, vec![]); + show(&mut app3, &bot_b, vec![]); + app3.ask_shown.insert(a, Instant::now() - std::time::Duration::from_secs(2)); + show(&mut app3, &bot_a, vec![enter]); + assert!(got_a.try_recv().is_err(), "back on the chat: its card waits a moment again"); } /// Esc that closes a menu closes the menu: it isn't a no to the step waiting in the chat.