From d64766e953e98ee2ad34d4a8bdcd96c68d733f51 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 15:17:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=95=8F=E9=A1=8C=E5=8D=A1=E6=90=AC?= =?UTF-8?q?=E9=80=B2=E8=81=8A=E5=A4=A9=E8=A3=A1=EF=BC=8C=E8=B7=9F=E8=A8=8A?= =?UTF-8?q?=E6=81=AF=E4=B8=80=E8=B5=B7=E4=B8=8A=E4=B8=8B=E6=8D=B2=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E5=86=8D=E8=93=8B=E4=BD=8F=E8=81=8A=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 問題卡(ask_person、/plan 的「照這個計畫做嗎?」)原本固定在輸入框上方、高度封在視窗的 45%, 選項一多就蓋住大半聊天,按鈕還被切在卡片裡面要再捲。 - 電腦:卡片是聊天最下面的一則,照內容多高就多高;出現和換下一題時聊天捲到它一次 (比視窗高時對齊卡片上緣,先看到題目),之後往上捲不會被拉回來。 - 手機:一樣放進聊天的捲動區(#askq)。 - 允許請求的黃色卡片不動,還是固定在輸入框上方。 - 功能地圖(chat、plan)和 FEATURES.md 一起改。 - 模式圖示的 id 從 Id::new 改成 Id::unique(上一個 commit 留下的過時用法警告)。 - 獨立審查沒有 P0/P1;修了它提的 4 個 P2(手機改成捲動區自己捲、同一個 call_id 的下一張卡 也會捲到、太高的卡對齊上緣、搜尋跳到訊息時不搶捲動)。 已驗證: cargo test 全綠(613,含 featuremap::、layout_audit::);截圖模式(示範資料、深色、760x560) 看過問題卡在聊天裡的樣子;mobile/index.html 的 script 解析得過。 未驗證: 「往上捲開再回來」沒有實際操作(截圖模式只有一張圖);手機網頁沒有在手機或瀏覽器上點過; 功能地圖 chat「驗證:」那一行要真的模型用問題卡問三件事,這次沒跑;大腦的螢幕(mirror)沒試。 Co-Authored-By: Claude Fable 5.2 --- FEATURES.md | 7 ++--- docs/feature-map/chat.md | 4 +-- docs/feature-map/plan.md | 2 +- mobile/index.html | 20 +++++++++++---- src/app.rs | 55 ++++++++++++++++++++++------------------ 5 files changed, 53 insertions(+), 35 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index 15bdb41..8dea54a 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -380,7 +380,8 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。 ### 問題卡(原版的 question card;2026-11-12) -- Bot 需要你做決定或補資料時,用 `ask_person` 在輸入框上方放一張黃色卡片問你,不再把一串問題寫成文字。這一回合會停下來等你。 +- Bot 需要你做決定或補資料時,用 `ask_person` 放一張黃色卡片問你,不再把一串問題寫成文字。這一回合會停下來等你。 +- 卡片在聊天最下面(最新一則訊息之後),跟聊天同一層、一起上下捲,照內容有多高就多高(以前固定在輸入框上方,選項一多就蓋住大半聊天、按鈕還要在卡片裡捲)。卡片出現和換下一題時聊天自己捲到它;往上捲看前面的內容不會被拉回來,按「↓」回到卡片。電腦和手機一樣。允許請求的黃色卡片(短)還是固定在輸入框上方。 - 一次最多 6 題,卡片一題一題走,左上寫「(Bot) 問你 · 2/3」。每題可以是: - **單選**:最多 8 個選項,點一下就選好並跳到下一題;最後一題點了就送出。 - **複選**(標「可以選好幾個」):打勾幾個都行,再按「下一題」或「送出」。 @@ -391,7 +392,7 @@ AnyBot 是一個桌面聊天 App,介面和運作方式照 Grok Bot 重做。 - 不按卡片、直接在輸入框打字送出:卡片收起來、算沒回答,Bot 照你打的做。 - Bot 收到的結果是「使用者的回答:1. (題目) → (答案)…」;聊天裡這一步顯示「問你 (第一題)(共 N 題)」,點開看得到答案。 - 側邊欄和面板在等的時候寫「等你回答」,輸入框上方那張臉旁邊也是;不在 App 前面時的通知標題是「(Bot) 問你」。 -- 手機版有同一張卡片(選項可點、可填寫、上一題、略過);打到一半畫面更新不會把字清掉。連到別台大腦的電腦上回答,答案會送回大腦。 +- 手機版有同一張卡片,也在聊天裡跟著捲(選項可點、可填寫、上一題、略過);打到一半畫面更新不會把字清掉。連到別台大腦的電腦上回答,答案會送回大腦。 - 密碼、卡號、驗證碼不走這張卡(Bot 被交代用保險庫或請你接手電腦)。訊息管道(Slack、Telegram…)和例行任務裡沒有人在 App 前面,Bot 被交代改用文字問。 - 打開「直接操作」不會替你回答問題卡或「需要處理」的卡片(以前會把「需要處理」當成「我完成了」)。 - 同一張問題卡問第二次、你給一樣的答案,不算「同一步重複」(那個檢查只管 Bot 自己重複做同樣的事)。 @@ -1620,7 +1621,7 @@ computer_use_screenshot、click、mouse_move、mouse_button(按住/放開) - **用法**:「/plan 要做的事」開始(Bot 正在做事時不行,先等它做完或按停止);「/plan」看計畫和進度;「/plan clear」取消(stop、取消…也可以)。電腦、大腦的螢幕、手機打的都算,由大腦處理;團隊的管理員也能用,成員和訊息管道打的不算指令。群組聊天還不能用;最多 4000 字。 - **計畫模式(還沒核准)**:Bot 只能看——讀檔、列資料夾、搜尋、讀網頁(web_fetch、瀏覽器打開/讀取/捲動)、截圖、查記憶和技能、查功能地圖。執行指令、改檔案、點擊、打字、送出、改設定在執行那一層就被擋下,回給 Bot「計畫還沒核准」(不是只靠提示詞,跟 Claude Code、Codex、Gemini CLI 一樣)。它先自己查清楚現況,查得到的不問;有你才能決定的取捨,用問題卡一次問完(最多 3 題、建議的放第一個),你略過就用建議的並寫成假設。 - **計畫卡**:Bot 用 submit_plan 交出計畫,聊天裡是一張「計畫」卡:一兩句摘要、照順序的步驟(通常 3 到 7 步,每步是一個看得到的結果,最後一步是驗證)、「怎麼確認做對了」、「注意」(假設、風險、花錢、對外送出、不能復原的)。只寫它建議的那一個做法。研究顯示錯的計畫比沒有計畫更糟,所以要求它根據查到的事實、寧可短而對。 - - **核准**:輸入框上方的問題卡「照這個計畫做嗎?」:「開始照計畫做」、「先不要」,或直接打字寫要改哪裡(它改完再交一張新卡,舊卡變「已修改,見下面新版」)。在卡片外傳訊息也算要修改;只有按「開始照計畫做」才算核准,不會等太久自己核准。按「先不要」或略過,計畫就取消,什麼都沒做。 + - **核准**:聊天最下面的問題卡「照這個計畫做嗎?」(跟聊天一起捲):「開始照計畫做」、「先不要」,或直接打字寫要改哪裡(它改完再交一張新卡,舊卡變「已修改,見下面新版」)。在卡片外傳訊息也算要修改;只有按「開始照計畫做」才算核准,不會等太久自己核准。按「先不要」或略過,計畫就取消,什麼都沒做。 - **照計畫做**:核准後同一輪接著做(不用再傳訊息),所有工具打開,第 1 步自動標成進行中;它每做完一步用 update_plan 更新一次(整份清單、同時只有一步進行中;不用每個小動作都更新——Manus 發現打勾佔了三分之一的動作)。計畫和實際不符就改清單並在訊息裡說為什麼,大改先問。卡上的步驟跟著打勾(✓ 做完、▸ 進行中、– 略過),輸入框上方臉的同一行右邊一個計畫圖示,旁邊寫「2/5」,滑過去看「照計畫做 · 2/5 · 現在這一步」和整份清單,點一下有「取消計畫」。全部做完那一輪結束時留一行「計畫完成:5 步都做完了。」,計畫清掉。 - **只管你自己的訊息**:例行任務、訊息管道和團隊成員的訊息照平常做,不受計畫模式限制。照計畫做的期間每一輪都帶著這份計畫(像 Claude Code 把核准的計畫交回給模型),所以聊別的事前先取消。清除聊天記錄、開始新對話會連計畫一起清掉;分享 Bot 的檔案不含計畫。重開 AnyBot 計畫還在;還沒核准時重開,傳一句話它就接著規劃。 - 手機一樣:計畫卡、問題卡都有;目標和計畫在輸入框上方是一排小圖示(計畫旁邊寫「2/5」),點一下展開那一行和「清除目標」/「取消計畫」。 diff --git a/docs/feature-map/chat.md b/docs/feature-map/chat.md index f1f26d4..a7e0e42 100644 --- a/docs/feature-map/chat.md +++ b/docs/feature-map/chat.md @@ -14,7 +14,7 @@ - 附件:「附加檔案」、拖進視窗、⌘V 貼圖。每個檔最多 50 MB,一個文字檔最多讀 20,000 字給模型。 - 長對話:用到「模型可讀長度」的 7 成,先收起舊步驟的長結果,不夠才把舊對話寫成摘要,聊天裡出現「較早的對話已整理成摘要」(「展開摘要」)。 - 卡住偵測:120 秒還沒開始回應,顯示「模型未能及時開始回應。請重試。」;開始後安靜 35 秒,顯示「回應中斷:模型超過 35 秒沒有送出任何內容。」。等你允許、工具在跑時不算。 -- 問題卡:Bot 用 `ask_person` 在輸入框上方放一張卡,一次最多 6 題、每題最多 8 個選項:單選、複選(「可以選好幾個」)或填寫(「輸入回答」)。每題都有「自己回答」的框;按鈕有「下一題」/「送出」「上一題」「略過」。 +- 問題卡:Bot 用 `ask_person` 在聊天最下面(最新一則訊息之後)放一張卡,跟聊天一起上下捲,不會蓋住聊天;卡片出現和換下一題時聊天會自己捲到它,往上捲看完內容再捲回來回答(輸入框上方的臉旁邊寫「等你回答」,按「↓」回到最下面)。一次最多 6 題、每題最多 8 個選項:單選、複選(「可以選好幾個」)或填寫(「輸入回答」)。每題都有「自己回答」的框;按鈕有「下一題」/「送出」「上一題」「略過」。 - 生活卡片(`show_card`):航班、地點、天氣、商品、活動,最多顯示 12 列,有網址時多一個「查看來源 ↗」。 - 表情:你可以對 Bot 的回答按表情(6 個常用加「更多表情符號」),Bot 下一輪看得到;Bot 用 `react` 在你的訊息上按表情。 - 重新看圖(`look_image`):較早的圖片在模型那邊只剩一段摘要時,Bot 請看得懂圖的模型,針對一個問題重看其中一張。 @@ -29,7 +29,7 @@ ## 怎麼操作 - Bot:要使用者做決定或補資料時用 `ask_person`(questions:question、options、multiple、default;已經知道的先填進 default),不要把一串問題寫成文字;查到航班、店家、天氣這類就用 `show_card`(kind、title、subtitle、rows、link);適合時用 `react`(emoji)按個表情;舊圖的摘要不夠(小字、精確數字)時用 `look_image`(index:0 是最新一張,附圖和截圖一起往回數;question 要具體)。 -- 驗證:送一則要用工具的訊息,工作中再送一句,要看到「已排入…」,Bot 在同一輪回應那句;按停止,送出鈕變回來、Bot 不再動作;在最後一則回答的 ⋯ 按「重新產生」,再按「還原上一個答案」,舊答案要回來;請 Bot「用問題卡問我三件事」,卡片要一題一題走,按「略過」後 Bot 照自己的判斷繼續。自動測試:`cargo test agent::`、`cargo test ask::`、`cargo test app::chat_ui::`、`cargo test attach::`、`cargo test app::tests::`、`cargo test layout_audit::`(最窄的視窗裡允許卡片的按鈕會換行、「已排入…」和輸入框的提示不會被切掉)。 +- 驗證:送一則要用工具的訊息,工作中再送一句,要看到「已排入…」,Bot 在同一輪回應那句;按停止,送出鈕變回來、Bot 不再動作;在最後一則回答的 ⋯ 按「重新產生」,再按「還原上一個答案」,舊答案要回來;請 Bot「用問題卡問我三件事」,卡片要出現在聊天最下面、能跟著聊天往上捲開,一題一題走,按「略過」後 Bot 照自己的判斷繼續。自動測試:`cargo test agent::`、`cargo test ask::`、`cargo test app::chat_ui::`、`cargo test attach::`、`cargo test app::tests::`、`cargo test layout_audit::`(最窄的視窗裡允許卡片的按鈕會換行、「已排入…」和輸入框的提示不會被切掉)。 ## 陷阱 diff --git a/docs/feature-map/plan.md b/docs/feature-map/plan.md index fde55a1..5244c6f 100644 --- a/docs/feature-map/plan.md +++ b/docs/feature-map/plan.md @@ -7,7 +7,7 @@ - 開始:「/plan 要做的事」(最多 4,000 字)。「/plan」看目前的計畫,「/plan clear」(或 stop、取消)取消。 - 計畫模式(還沒核准):只能看——讀檔、列資料夾、搜尋、`web_fetch`、瀏覽器的打開/讀取/捲動、截圖、查記憶和技能、`anybot_guide`。執行指令、改檔案、點擊、打字、送出、改設定都會被擋下(擋在執行那一層,不是只靠提醒)。有使用者才能決定的取捨,用問題卡一次問完(最多 3 題,建議的選項在第一個);略過的話 Bot 用建議的那個,寫成假設。 - 計畫卡:Bot 用 `submit_plan` 交出計畫,聊天裡出現一張「計畫」卡:一兩句摘要、照順序的步驟(通常 3 到 7 步,最後一步是驗證)、「怎麼確認做對了」、「注意」(假設、風險、會花錢或對外送出的地方)。卡右上角寫狀態:等你決定、照著做 · 2/5、已核准、已修改(見下面新版)、沒有採用;修改過或沒採用的只剩摘要。 -- 核准:輸入框上方的問題卡「照這個計畫做嗎?」:「開始照計畫做」、「先不要」,或直接打字寫要改哪裡(Bot 改完再交一張新卡)。在卡片之外傳訊息也算要修改;只有按「開始照計畫做」才算核准,不會自己過期核准。 +- 核准:聊天最下面的問題卡「照這個計畫做嗎?」(跟聊天一起捲):「開始照計畫做」、「先不要」,或直接打字寫要改哪裡(Bot 改完再交一張新卡)。在卡片之外傳訊息也算要修改;只有按「開始照計畫做」才算核准,不會自己過期核准。 - 照計畫做:核准後同一輪接著做,工具全部打開,第 1 步自動標成進行中。Bot 每做完一步用 `update_plan` 更新一次(整份清單,同時只有一步進行中);計畫和實際不符就改清單並說為什麼,大改先問。計畫卡上的步驟跟著打勾(✓ 做完、▸ 進行中、– 略過)。 - 完成:全部步驟做完(或略過)那一輪結束時,聊天裡留一行「計畫完成:5 步都做完了。」,計畫清掉。 diff --git a/mobile/index.html b/mobile/index.html index f236eec..a561462 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -288,6 +288,9 @@ details.dt>.dt-in{padding-left:var(--sp-4);margin-top:var(--sp-2)} .mode::after{content:"";position:absolute;inset:-8px -2px} .mode.on .ic{color:var(--accent)} .mode.open{box-shadow:inset 0 0 0 1px var(--text3)} +/* 問題卡: in the chat, after the newest message (it scrolls with it), as tall as its content. */ +#askq{padding:0 14px} +#askq .ask{max-height:none;overflow:visible;margin:4px auto 14px} .goalbar{max-width:560px;margin:0 auto 6px;display:flex;align-items:center;gap:8px;font-size:var(--fs-small);color:var(--text2);background:var(--hover);border-radius:var(--r-m);padding:5px 6px 5px 11px} .goalbar .t{flex:1;min-width:0;display:flex;align-items:center;gap:6px} .goalbar .t span{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} @@ -611,7 +614,7 @@ button,.row,.ib,.island,.opt,.chip,.tab,label.sw,[role="button"]{-webkit-user-se -
+
@@ -1568,8 +1571,9 @@ function renderDock() { const b = bot(S.open) || {}; const a = S.approvals.find((x) => x.bot === S.open); clearInterval(thumbTimer); - if (a && a.kind === "question" && owner()) { renderQuestion(a); renderDockRest(b); return; } + if (a && a.kind === "question" && owner()) { $("ask").innerHTML = ""; renderQuestion(a); renderDockRest(b); return; } ASKF = null; + $("askq").innerHTML = ""; if (!a) $("ask").innerHTML = ""; else if (!owner()) $("ask").innerHTML = `
${esc(a.title)}
等擁有者或管理員決定
`; else if (a.kind === "handoff") { @@ -1608,12 +1612,18 @@ function renderQuestion(a, force) { ASKF = {id: a.call_id, step: 0, drawn: -1, picks: qs.map((q) => { const k = (q.options || []).indexOf(q.default); return k >= 0 && q.default ? [k] : []; }), typed: qs.map((q) => (q.options || []).length ? "" : (q.default || ""))}; } // Drawn already: leave it, or what is being typed would be lost on every refresh. - if (!force && ASKF.drawn === ASKF.step && $("ask").querySelector(".own")) return; + if (!force && ASKF.drawn === ASKF.step && $("askq").querySelector(".own")) return; const i = ASKF.step, q = qs[i], opts = q.options || [], last = i + 1 === qs.length; ASKF.drawn = i; const own = !!(ASKF.typed[i] || "").trim(); - $("ask").innerHTML = `
${esc(a.title)}${qs.length > 1 ? ` · ${i + 1}/${qs.length}` : ""}
${esc(q.question)}
${q.multiple ? "可以選好幾個" : ""}
${opts.map((o, k) => ``).join("")}
${i > 0 ? `` : ""}
`; - const box = $("ask"), field = box.querySelector(".own"), go = box.querySelector('[data-go="next"]'); + $("askq").innerHTML = `
${esc(a.title)}${qs.length > 1 ? ` · ${i + 1}/${qs.length}` : ""}
${esc(q.question)}
${q.multiple ? "可以選好幾個" : ""}
${opts.map((o, k) => ``).join("")}
${i > 0 ? `` : ""}
`; + const box = $("askq"), field = box.querySelector(".own"), go = box.querySelector('[data-go="next"]'); + // The chat comes to the card when it appears and at each next question. + // (Once laid out; a card taller than the screen shows its question, not its buttons.) + requestAnimationFrame(() => { + const sc = $("scroller"), top = box.getBoundingClientRect().top - sc.getBoundingClientRect().top + sc.scrollTop; + sc.scrollTo({top: box.offsetHeight > sc.clientHeight ? top : sc.scrollHeight, behavior: "smooth"}); + }); const ready = () => { go.disabled = !askAnswer(q, i); }; ready(); const send = async (body) => { ASKF = null; box.innerHTML = ""; try { await api(base() + `api/bots/${(a && a.target) || S.open}/answer`, {json: body}); } catch (e) { toast(e.message); } }; diff --git a/src/app.rs b/src/app.rs index 59eb196..7d2c112 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2711,7 +2711,7 @@ impl App { } // (An id of its own: the popup stays open while cards come and go above.) let (rect, _) = at.allocate_exact_size(vec2(26.0, 26.0), egui::Sense::hover()); - let r = at.interact(rect, egui::Id::new(("mode", bot.id, m.end)), egui::Sense::click()).on_hover_cursor(egui::CursorIcon::PointingHand); + let r = at.interact(rect, egui::Id::unique(("mode", bot.id, m.end)), egui::Sense::click()).on_hover_cursor(egui::CursorIcon::PointingHand); if r.hovered() { at.painter().rect_filled(rect, 7.0, p.hover); } @@ -3706,7 +3706,8 @@ impl App { } self.sending_bubbles(ui, &bot); // (What it is doing, and a request, sit above the input: see composer. - // A hand-off keeps its card here, with the live screen.) + // A hand-off keeps its card here, with the live screen; so does a + // question — it scrolls with the chat instead of covering it.) self.approval_card(ui, ctx, &bot); ui.add_space(16.0); // Last in the content, so no code block's own scroll area takes it. @@ -3917,8 +3918,11 @@ impl App { fn approval_card(&mut self, ui: &mut egui::Ui, ctx: &egui::Context, bot: &Bot) { let p = self.pal; let _ = p; - if self.approvals.get(&bot.id).map(|a| a.kind) == Some(ApprovalKind::Handoff) { - self.handoff_card(ui, ctx, bot); + match self.approvals.get(&bot.id).map(|a| a.kind) { + Some(ApprovalKind::Handoff) => self.handoff_card(ui, ctx, bot), + Some(ApprovalKind::Question) => self.question_card(ui, ctx, bot), + // (The next card comes into view again, even one with the same id.) + _ => ui.data_mut(|d| d.remove::<(String, usize)>(egui::Id::unique(("ask-seen", bot.id)))), } } @@ -3930,8 +3934,8 @@ impl App { /// `enter`: the composer took a plain Enter that is this card's (the box is empty). fn approval_dock(&mut self, ui: &mut egui::Ui, ctx: &egui::Context, bot: &Bot, draft_empty: bool, typing: bool, enter: bool) { let p = self.pal; + // (A question's card is in the chat: see question_card.) if self.approvals.get(&bot.id).is_some_and(|a| a.kind == ApprovalKind::Question) { - self.question_dock(ui, ctx, bot); return; } self.ask_forms.remove(&bot.id); @@ -3991,11 +3995,13 @@ impl App { self.mark(); } - /// 問題卡, docked above the input like a request: one question at a time. A choice is one - /// click (it moves on, and on the last question sends); several choices and typed answers - /// have 下一題/送出. 「自己回答」 is always there, and so is writing a message instead, which - /// leaves the card unanswered. - fn question_dock(&mut self, ui: &mut egui::Ui, ctx: &egui::Context, bot: &Bot) { + /// 問題卡, the last thing in the chat (it used to be docked above the input, where a card + /// with several choices covered most of what the bot had just said): it scrolls with the + /// messages, as tall as its content, and the chat comes to it when it appears or moves to + /// the next question. One question at a time. A choice is one click (it moves on, and on + /// the last question sends); several choices and typed answers have 下一題/送出. 「自己回答」 + /// is always there, and so is writing a message instead, which leaves the card unanswered. + fn question_card(&mut self, ui: &mut egui::Ui, ctx: &egui::Context, bot: &Bot) { let p = self.pal; let Some(a) = self.approvals.get(&bot.id) else { return }; let call_id = a.call_id.clone(); @@ -4013,12 +4019,11 @@ impl App { Skip, } let mut act = None; - // (選項再多也不許把輸入框頂出螢幕:卡面照內容估高、照視窗高度封頂,裡面在卡面裡往下捲。) - let cap = (ui.ctx().content_rect().height() * 0.45).max(160.0); - let body = ask_card_height(q, ui.available_width(), cap); + ui.add_space(10.0); + let top = ui.cursor().top(); needs_you_card(ui, p, |ui| { ui.set_width(ui.available_width()); - egui::ScrollArea::vertical().id_salt(("ask-dock", bot.id, call_id.clone())).max_height(body).min_scrolled_height(body).auto_shrink([false, false]).show(ui, |ui| { + ui.vertical(|ui| { if qs.len() > 1 { ui.label(RichText::new(format!("{} 問你 · {}/{}", bot.name, step + 1, qs.len())).size(FONT_SM).color(p.text2)); } else { @@ -4089,6 +4094,18 @@ impl App { }); }); }); + // The chat comes to the card once for each question (after that the person scrolls as + // they like: up to read what it is about, back down to answer). + let seen_id = egui::Id::unique(("ask-seen", bot.id)); + let now_at = (call_id.clone(), step); + // (Not while a search is taking the chat to a message: the card's turn comes after.) + if self.goto.is_none() && ui.data(|d| d.get_temp::<(String, usize)>(seen_id)).as_ref() != Some(&now_at) { + ui.data_mut(|d| d.insert_temp(seen_id, now_at)); + let card = egui::Rect::from_min_max(egui::pos2(ui.min_rect().left(), top), egui::pos2(ui.min_rect().right(), ui.cursor().top() + 16.0)); + // A card taller than the window shows its question, not its buttons. + let tall = card.height() > ui.clip_rect().height(); + ui.scroll_to_rect(card, Some(if tall { Align::TOP } else { Align::BOTTOM })); + } ui.add_space(6.0); match act { Some(Act::Skip) => self.answer(ctx, bot.id, ApprovalAnswer::Reject), @@ -7324,12 +7341,6 @@ fn ask_dock_height(reason: &str, width: f32, cap: f32) -> f32 { (wrapped_lines(detail, (width - 92.0).max(120.0), cw) * 17.0 + 168.0).min(cap) } -/// The question card's content height: header + question + option rows + field + buttons. -fn ask_card_height(q: &crate::ask::Question, width: f32, cap: f32) -> f32 { - let q_lines = wrapped_lines(&q.question, (width - 64.0).max(120.0), 16.0); - (26.0 + q_lines * 21.0 + q.options.len() as f32 * 44.0 + 122.0).min(cap) -} - fn composer_box_h(text_h: f32, max_h: f32) -> f32 { (text_h + COMPOSER_TOP + 3.0).clamp(28.0, max_h.max(28.0)) } @@ -9062,10 +9073,6 @@ mod tests { assert!((1.0..=cap + 0.01).contains(&short), "short {short} cap {cap} w {width}"); assert!((1.0..=cap + 0.01).contains(&long), "long {long} cap {cap} w {width}"); assert!(long >= short, "a longer reason got a shorter card at w {width}"); - let q = |n: usize| crate::ask::Question { question: "請選一個要彙整的資料夾".into(), options: (0..n).map(|i| format!("選項 {i}")).collect(), multiple: false, default: String::new() }; - let (few, many) = (ask_card_height(&q(2), width, cap), ask_card_height(&q(8), width, cap)); - assert!((1.0..=cap + 0.01).contains(&few) && (1.0..=cap + 0.01).contains(&many), "question card over the cap at w {width}"); - assert!(many >= few, "more options made the card shorter at w {width}"); } } // The composer's box: at least one row, never past its own cap.