Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Add a copy button to each message and answer in the conversation (#828)

BFlatcd6dbdf41c43
diff --git a/crates/ui-egui/src/chat.rs b/crates/ui-egui/src/chat.rs
index b6c0a72a..8ee0323f 100644
--- a/crates/ui-egui/src/chat.rs
+++ b/crates/ui-egui/src/chat.rs
@@ -362,26 +362,60 @@ enum ChatAction {
OpenLog(std::path::PathBuf),
}
+/// The side of a message's copy button.
+const COPY: f32 = 22.0;
+
+fn margin(dense: bool) -> Margin {
+ if dense { Margin::symmetric(10, 6) } else { Margin::symmetric(16, 12) }
+}
+
pub(crate) fn bubble(t: &Tokens, user: bool, dense: bool) -> egui::Frame {
let fill = if user { t.accent_soft } else { t.card };
let stroke = if user { egui::Stroke::NONE } else { egui::Stroke::new(1.0, t.card_border) };
- let m = if dense { Margin::symmetric(10, 6) } else { Margin::symmetric(16, 12) };
- egui::Frame::new().fill(fill).stroke(stroke).corner_radius(t.r_lg()).inner_margin(m)
+ egui::Frame::new().fill(fill).stroke(stroke).corner_radius(t.r_lg()).inner_margin(margin(dense))
}
-/// The person's message on the right. Labels in a right-to-left row don't wrap by themselves,
-/// so a long prompt would run off the side: wrap it inside the bubble.
+/// A button at `at` that copies a whole message (#825: selecting text in the feed is
+/// unreliable). Shown while the pointer is over the message (`over`) or the button has keyboard
+/// focus; it's always laid out, so Tab reaches it.
+fn copy_button(ui: &mut Ui, over: egui::Rect, at: egui::Pos2, text: &str) {
+ let at = egui::Rect::from_min_size(at, Vec2::splat(COPY));
+ let mut slot = ui.new_child(egui::UiBuilder::new().max_rect(at));
+ if !(ui.rect_contains_pointer(over.union(at)) || ui.memory(|m| m.has_focus(slot.next_auto_id()))) {
+ slot.set_opacity(0.0);
+ }
+ if icons::button(&mut slot, "copy", COPY, false, "Copy the message").clicked() {
+ ui.ctx().copy_text(text.to_owned());
+ }
+}
+
+/// The person's message on the right, with its copy button beside it. Labels in a right-to-left
+/// row don't wrap by themselves, so a long prompt would run off the side: wrap it inside the bubble.
pub(crate) fn user_bubble(ui: &mut Ui, text: &str, dense: bool) {
let t = Tokens::get(ui.ctx());
ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| {
- bubble(&t, true, dense).show(ui, |ui| {
- ui.set_max_width(ui.available_width().min(560.0));
+ let shown = bubble(&t, true, dense).show(ui, |ui| {
+ ui.set_max_width((ui.available_width() - COPY - 4.0).min(560.0));
// The bubble sits on the right; its lines still read from the left.
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
ui.add(egui::Label::new(RichText::new(text).color(t.text)).wrap());
});
});
+ let r = shown.response.rect;
+ copy_button(ui, r, egui::pos2(r.left() - COPY - 4.0, r.top() + f32::from(margin(dense).top) - 1.0), text);
+ });
+}
+
+/// An answer in its bubble, with its copy button in a column of its own on the right, so it
+/// never covers the text.
+pub(crate) fn answer_bubble(ui: &mut Ui, dense: bool, text: &str, content: impl FnOnce(&mut Ui)) {
+ let t = Tokens::get(ui.ctx());
+ let shown = bubble(&t, false, dense).show(ui, |ui| {
+ ui.set_width(ui.available_width());
+ ui.allocate_ui_with_layout(Vec2::new((ui.available_width() - COPY - 4.0).max(0.0), 0.0), egui::Layout::top_down(egui::Align::Min), content);
});
+ let (r, m) = (shown.response.rect, margin(dense));
+ copy_button(ui, r, egui::pos2(r.right() - f32::from(m.right) - COPY, r.top() + f32::from(m.top) - 1.0), text);
}
/// A one-line activity row (icon and text) that wraps instead of running off the side.
@@ -398,8 +432,7 @@ fn item_ui(ui: &mut Ui, item: &ChatItem, beginner: bool, dense: bool, open: bool
match item {
ChatItem::User(text) => user_bubble(ui, text, dense),
ChatItem::Assistant { text, backend, streaming } => {
- bubble(&t, false, dense).show(ui, |ui| {
- ui.set_width(ui.available_width());
+ answer_bubble(ui, dense, text, |ui| {
rich_text(ui, text, beginner && !dense);
if *streaming {
widgets::thinking(ui);
@@ -675,6 +708,23 @@ fn code_block(ui: &mut Ui, code: &str, t: &Tokens) {
mod tests {
use super::*;
+ /// #825: the person's message and the answer each have a button that copies all of it.
+ #[test]
+ fn a_message_is_copied_whole() {
+ use egui_kittest::{Harness, kittest::Queryable};
+ let text = "Run `cargo build` in the app folder,\nthen open it.";
+ for item in [ChatItem::User(text.into()), ChatItem::Assistant { text: text.into(), backend: None, streaming: false }] {
+ let mut h = Harness::builder().build_ui(move |ui| {
+ theme::install_fonts(ui.ctx());
+ item_ui(ui, &item, false, false, false, &mut Vec::new());
+ });
+ h.get_by_label("Copy the message").click();
+ h.step();
+ let commands = &h.output().platform_output.commands;
+ assert!(commands.iter().any(|c| matches!(c, egui::OutputCommand::CopyText(t) if t == text)), "{commands:?}");
+ }
+ }
+
#[test]
fn events_fold_into_a_tidy_conversation() {
let mut chat = vec![ChatItem::User("hi".into())];
diff --git a/crates/ui-egui/src/fr.tsv b/crates/ui-egui/src/fr.tsv
index d4d0df15..ad2a6f35 100644
--- a/crates/ui-egui/src/fr.tsv
+++ b/crates/ui-egui/src/fr.tsv
@@ -877,3 +877,4 @@ Close window Fermer la fenêtre
Full screen Plein écran
Zoom Réduire/agrandir
Bring all to front Tout ramener au premier plan
+Copy the message Copier le message
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 5acfe1c7..9736aa42 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -1442,3 +1442,4 @@ Close window Zavřít okno
Full screen Celá obrazovka
Zoom Zvětšit
Bring all to front Vše do popředí
+Copy the message Zkopírovat zprávu
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index cfc004d3..2badea0f 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -1442,3 +1442,4 @@ Close window Fenster schließen
Full screen Vollbild
Zoom Zoomen
Bring all to front Alle nach vorne bringen
+Copy the message Die Nachricht kopieren
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index dc757bc1..e63650c3 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -1442,3 +1442,4 @@ Close window 윈도우 닫기
Full screen 전체 화면
Zoom 확대/축소
Bring all to front 모두 앞으로 가져오기
+Copy the message 메시지 복사
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index ec72a916..d64a76fb 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -1442,3 +1442,4 @@ Close window Закрыть окно
Full screen Полноэкранный режим
Zoom Изменить масштаб
Bring all to front Все окна — на передний план
+Copy the message Скопировать сообщение
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index a1846324..c8eb4a32 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -1442,3 +1442,4 @@ Close window 关闭窗口
Full screen 全屏幕
Zoom 缩放
Bring all to front 前置全部窗口
+Copy the message 复制这条消息
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 519cbcc7..6de1c5ae 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -1442,3 +1442,4 @@ Close window 關閉視窗
Full screen 全螢幕
Zoom 縮放
Bring all to front 將全部視窗移至最前
+Copy the message 複製這則訊息
diff --git a/crates/ui-egui/src/ja.tsv b/crates/ui-egui/src/ja.tsv
index 4727c826..8f0e716a 100644
--- a/crates/ui-egui/src/ja.tsv
+++ b/crates/ui-egui/src/ja.tsv
@@ -879,3 +879,4 @@ Close window ウインドウを閉じる
Full screen フルスクリーン
Zoom 拡大/縮小
Bring all to front すべてを手前に移動
+Copy the message メッセージをコピー
diff --git a/crates/ui-egui/src/project.rs b/crates/ui-egui/src/project.rs
index c0d95982..6de1e1b9 100644
--- a/crates/ui-egui/src/project.rs
+++ b/crates/ui-egui/src/project.rs
@@ -1321,8 +1321,7 @@ fn draw_items(
FeedItem::Step { text, .. } => chat::activity_row(ui, RichText::new(text).color(t.text_dim).size(theme::SMALL)),
FeedItem::Paused => chat::activity_row(ui, RichText::new(tr("Paused.")).color(t.text_dim).size(theme::SMALL)),
FeedItem::Agent { text, streaming } => {
- chat::bubble(&t, false, false).show(ui, |ui| {
- ui.set_width(ui.available_width());
+ chat::answer_bubble(ui, false, text.trim(), |ui| {
chat::rich_text(ui, text.trim(), !advanced);
if *streaming {
widgets::thinking(ui);
diff --git a/docs/STATUS.md b/docs/STATUS.md
index d6a754a6..b211a44b 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -48,7 +48,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi
| WebAssembly tag interfaces | `formats_wasm_compare` resolves retained imported and defined tag exports to their declared parameter types. Identical unresolved or invalid diagnostics may still count as unchanged; those counts do not establish interface compatibility, and invalid/partial limitations remain present | Synthetic core modules with tag changes and re-exports, mixed index spaces, import/tag limits, and missing or non-function type references; formats and engine tests. No real module corpus or WebAssembly execution was used for this correction |
| Questions and approvals | A file inbox per project; `core_person_ask`, `core_action_approve` and MCP consent requests become cards in the app | Cross-handle round-trip tests, a full approval round trip through the engine |
| Runtime assets in pinned builds | Frozen and light pins, size estimates and project copies keep runtime files in `obj` folders. An `obj` directory beside a regular C#, F# or Visual Basic project file is still recognised as compiler output; ambiguous folders are retained. New pins record the direct-launch program relative to the copy so a newer helper cannot replace it; older pins retain discovery behavior | Synthetic filesystem tests cover both pin modes, model bytes, compiler-output controls and project duplication. A Linux tool-level regression starts temporary scripts through `project_pin_open`, with a newer `Build/obj/helper`, and verifies the originally selected program and its output; a missing recorded program is refused. No real pinned application was launched for this correction |
-| Desktop app | Simple mode: sidebar with New project and the project history (kept across restarts); New project makes something, works on a project the person already has (Work on my project: its folder's files are the app, edited in place without a question, and the project takes the folder's name), or just looks inside an app or file, a website or a game's files; a Game files screen (a game's archives; pictures from Unreal paks, Unity .assets files and Unity bundles saved as PNG after the person confirms they may unpack the game; uncompressed textures and the block formats DXT1, DXT5 and BC4–BC7), make prompt with picture attachments (picked, dropped, or pasted with Ctrl+V, shown as picture tiles) and, for anything recreated, a Clean room / Deep choice (also in the title bar; in Clean room, Just look inside, Game files, opening a file and the workbench ask for Deep mode instead), project screen (steps with the time spent and the AI cost and tokens of every build, saved in the project's usage.json by the run (a coding agent's figure is shown as an estimate at API prices, not the bill), what the build is on now and its activity as it arrives (kept in `build-activity.log`), pinned builder checklist (its X folds it away between builds, kept in the project, `project_plan_fold`; a later run's checklist shows again), feed, question and approval cards, a Continue card when a build was paused or stopped part-way (the app or computer closed; the project shows Interrupted) that carries on the builder's own session instead of starting over, and "It's done" beside Continue or Try again to keep the build as it is (`project_build_finish`), checks with screenshots and the requirements not met yet, the builder's open questions, preview, play, folder, follow-ups while it builds, which Claude Code takes at its next step; Up in the prompt box takes back the last note still waiting). Projects can start in a folder the person picks, whose files are either the app, edited in place (its stack read from those files unless the request names another, and, with nothing to recreate, judged by its own build and tests, whatever it's written in), or material to start from (asked, or the answer remembered in Settings), and are listed from any number of folders (`project_folders`, `project_list`, `rebuild --project-folder`). Make says which AI builds ("Built by": automatic, or any AI that can build, by name); a pick stays with the project and builds its later changes. With nothing to build with, Start offers the coding agents found on the computer. Settings → AI turns an AI off or removes it, and sets how hard the Claude API or Claude Code thinks (every Claude level, low to max; also `ai effort` in the CLI). Each Claude Code AI can keep its sign-in in a folder of its own (its `CLAUDE_CONFIG_DIR`, so its own account; `ai folder` in the CLI, a folder on that computer over SSH), used for its runs, its sign-in check and its kept session, and Add another adds a second Claude Code for a second account. In the prompt box, Up at the very start and Down at the very end go through earlier prompts when no note is waiting. Questions about a build ("Just ask" under the prompt box, or a message starting with `/btw`, the first slash command; `rebuild_question_ask`) are answered in the conversation, where each folds away and is kept in the project, without a build or a round and changing nothing: Claude Code answers from a read-only copy of the builder's own session. Under each project's prompt box, "Builder's questions: Ask me / Decide yourself" chooses whether the builder's questions come to the person as cards or are decided by the builder, which says what it chose (`project_questions_set`; the default is in Settings and follows Auto mode until picked). Projects can be renamed, duplicated and deleted (right-click in the sidebar, or the project's page; a delete keeps the person's own files). A build can be pinned (Pin this build on its page, or `project_pin_*` from the CLI and MCP): a frozen copy in the project's pinned/ folder (the default) or a light one that shares dependencies and media with the project through hard links (each one's size shown first), opened from the sidebar's collapsible Pinned section (icons with a running dot when folded); a pin or Play runs once per folder unless another copy is asked for, and a start that quits at once says so with its last output. Typed drafts survive a restart. In a narrow window the sidebar folds to icons and the project's details move above its feed; messages float over the screen and errors stay until dismissed. Advanced mode: workbench with every panel wired to real tools, as a screen beside the projects (builds and their questions stay a click away). On macOS the menu bar has the app's actions (open, new project, settings, Simple / Advanced, Clean room / Deep, the command palette, help) with the usual shortcuts | UI unit and smoke tests (egui_kittest), offscreen snapshots of every screen |
+| Desktop app | Simple mode: sidebar with New project and the project history (kept across restarts); New project makes something, works on a project the person already has (Work on my project: its folder's files are the app, edited in place without a question, and the project takes the folder's name), or just looks inside an app or file, a website or a game's files; a Game files screen (a game's archives; pictures from Unreal paks, Unity .assets files and Unity bundles saved as PNG after the person confirms they may unpack the game; uncompressed textures and the block formats DXT1, DXT5 and BC4–BC7), make prompt with picture attachments (picked, dropped, or pasted with Ctrl+V, shown as picture tiles) and, for anything recreated, a Clean room / Deep choice (also in the title bar; in Clean room, Just look inside, Game files, opening a file and the workbench ask for Deep mode instead), project screen (steps with the time spent and the AI cost and tokens of every build, saved in the project's usage.json by the run (a coding agent's figure is shown as an estimate at API prices, not the bill), what the build is on now and its activity as it arrives (kept in `build-activity.log`), pinned builder checklist (its X folds it away between builds, kept in the project, `project_plan_fold`; a later run's checklist shows again), feed (each message and answer has a copy button, shown on hover or keyboard focus, #825), question and approval cards, a Continue card when a build was paused or stopped part-way (the app or computer closed; the project shows Interrupted) that carries on the builder's own session instead of starting over, and "It's done" beside Continue or Try again to keep the build as it is (`project_build_finish`), checks with screenshots and the requirements not met yet, the builder's open questions, preview, play, folder, follow-ups while it builds, which Claude Code takes at its next step; Up in the prompt box takes back the last note still waiting). Projects can start in a folder the person picks, whose files are either the app, edited in place (its stack read from those files unless the request names another, and, with nothing to recreate, judged by its own build and tests, whatever it's written in), or material to start from (asked, or the answer remembered in Settings), and are listed from any number of folders (`project_folders`, `project_list`, `rebuild --project-folder`). Make says which AI builds ("Built by": automatic, or any AI that can build, by name); a pick stays with the project and builds its later changes. With nothing to build with, Start offers the coding agents found on the computer. Settings → AI turns an AI off or removes it, and sets how hard the Claude API or Claude Code thinks (every Claude level, low to max; also `ai effort` in the CLI). Each Claude Code AI can keep its sign-in in a folder of its own (its `CLAUDE_CONFIG_DIR`, so its own account; `ai folder` in the CLI, a folder on that computer over SSH), used for its runs, its sign-in check and its kept session, and Add another adds a second Claude Code for a second account. In the prompt box, Up at the very start and Down at the very end go through earlier prompts when no note is waiting. Questions about a build ("Just ask" under the prompt box, or a message starting with `/btw`, the first slash command; `rebuild_question_ask`) are answered in the conversation, where each folds away and is kept in the project, without a build or a round and changing nothing: Claude Code answers from a read-only copy of the builder's own session. Under each project's prompt box, "Builder's questions: Ask me / Decide yourself" chooses whether the builder's questions come to the person as cards or are decided by the builder, which says what it chose (`project_questions_set`; the default is in Settings and follows Auto mode until picked). Projects can be renamed, duplicated and deleted (right-click in the sidebar, or the project's page; a delete keeps the person's own files). A build can be pinned (Pin this build on its page, or `project_pin_*` from the CLI and MCP): a frozen copy in the project's pinned/ folder (the default) or a light one that shares dependencies and media with the project through hard links (each one's size shown first), opened from the sidebar's collapsible Pinned section (icons with a running dot when folded); a pin or Play runs once per folder unless another copy is asked for, and a start that quits at once says so with its last output. Typed drafts survive a restart. In a narrow window the sidebar folds to icons and the project's details move above its feed; messages float over the screen and errors stay until dismissed. Advanced mode: workbench with every panel wired to real tools, as a screen beside the projects (builds and their questions stay a click away). On macOS the menu bar has the app's actions (open, new project, settings, Simple / Advanced, Clean room / Deep, the command palette, help) with the usual shortcuts | UI unit and smoke tests (egui_kittest), offscreen snapshots of every screen |
| CLI | Every tool, `--deep` or `--clean-room` for one run (never saved), `rebuild` (including `--continue-in`, and `--resume` to carry on a stopped build), `mcp --inbox`, `ai`, `setup`, `doctor`, `report` | CLI integration tests |
| SQLite database files (`db_sqlite_show`) | A rowid alias column (`INTEGER PRIMARY KEY`, including the table-constraint form) shows the rowid; `DESC`, non-`INTEGER` and composite keys keep their stored values | Hand-built fixtures; generated files compared with the official SQLite library |
| SQLite WITHOUT ROWID tables | Read from the index b-tree, interior records and overflow included; rows in primary-key order, values in declaration order, `rowid` null | Hand-built fixtures; generated files compared with the official SQLite library |