Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Agent chat: drops on the popped-out window attach (#2812) (#2861)

bherbruckd9c3fdb80f11
diff --git a/crates/ui-egui/src/agent_chat/panel.rs b/crates/ui-egui/src/agent_chat/panel.rs
index 354185a2dc..8f6c792c2d 100644
--- a/crates/ui-egui/src/agent_chat/panel.rs
+++ b/crates/ui-egui/src/agent_chat/panel.rs
@@ -87,6 +87,7 @@ pub fn show(app: &mut SolveApp, ui: &mut egui::Ui) {
#[cfg(not(target_arch = "wasm32"))]
if app.preferences.agent_chat_popped {
window(app, &ctx);
+ show_drop_hint(app, &ctx);
return;
}
let t = Tokens::get();
@@ -304,12 +305,24 @@ fn window(app: &mut SolveApp, ctx: &egui::Context) {
// The picture viewer opens over this window, where the click was, not over the main one.
gallery_window(app, ui.ctx());
if class == egui::ViewportClass::EmbeddedWindow {
- // Floating inside the app: its handles are the main window's, as the panel's are.
+ // Floating inside the app: its handles are the main window's, as the panel's are. The
+ // app's own drop handling sees the drops, so the window counts as the chat's place
+ // (the hint is drawn by the caller).
crate::scenario::publish_rect("agent_chat:window", r.response.rect);
app.agent_chat.panel_rect = Some(r.response.rect);
+ app.agent_chat.drop_rect = Some(r.response.rect);
return;
}
let ctx = ui.ctx().clone();
+ // A window of its own gets the drops made on it: the whole window is the chat, so there
+ // is no pointer to ask about (the main window's handling never sees them).
+ let dropped = ctx.input_mut(|i| std::mem::take(&mut i.raw.dropped_files));
+ if !dropped.is_empty() {
+ attach_dropped(app, dropped.iter().map(|f| f.path().to_path_buf()));
+ }
+ if ctx.input(|i| !i.raw.hovered_files.is_empty()) {
+ drop_hint(&ctx, r.response.rect);
+ }
if ctx.input_mut(|i| i.consume_shortcut(&SHORTCUT)) {
toggle(app);
}
diff --git a/crates/ui-egui/src/agent_chat/tests.rs b/crates/ui-egui/src/agent_chat/tests.rs
index 95756ff92c..e0211bb9d0 100644
--- a/crates/ui-egui/src/agent_chat/tests.rs
+++ b/crates/ui-egui/src/agent_chat/tests.rs
@@ -1348,6 +1348,34 @@ fn files_dropped_on_the_chat_attach_and_the_app_does_not_open_them() {
let _ = std::fs::remove_dir_all(&d);
}
+/// The chat popped out into its own window takes drops too, and says so while files are dragged
+/// over it (#2812). Here the window floats inside the app, as it does where the system can't open
+/// one: a drop on the window is the chat's, one elsewhere is not.
+#[test]
+fn files_dropped_on_the_popped_out_chat_attach() {
+ use crate::scenario::rect_of;
+ let d = attachable("popdrop");
+ let mut h = narrow_chat();
+ h.call("ui.resize", json!({"width": 1600, "height": 1000}));
+ h.app.preferences.agent_chat_popped = true;
+ h.frames(4);
+ let window = rect_of("agent_chat:window").expect("popped out");
+ let hovered = || vec![egui::HoveredFile { path: Some(d.join("target.png")), mime: String::new() }];
+ h.drag_files(window.center(), hovered(), Vec::new());
+ assert!(rect_of("agent_chat:drop_hint").is_some_and(|r| window.contains(r.center())), "the hint over the window");
+ let outside = egui::pos2(5.0, 500.0);
+ assert!(!window.contains(outside));
+ h.drag_files(outside, hovered(), Vec::new());
+ assert!(rect_of("agent_chat:drop_hint").is_none(), "no hint away from it");
+ drop_files(&mut h, window.center(), &[d.join("target.png"), d.join("brief.md")]);
+ settle_chat(&mut h);
+ assert_eq!(status(&h.app)["attachments"], json!(["target.png", "brief.md"]));
+ assert!(!h.app.file_load.busy(), "the app doesn't open them as well");
+ drop_files(&mut h, outside, &[d.join("brief.md")]);
+ assert_eq!(status(&h.app)["attachments"].as_array().map(Vec::len), Some(2), "away from the window: not the chat's");
+ let _ = std::fs::remove_dir_all(&d);
+}
+
/// Many files and a long message in a narrow chat: the chips wrap onto more rows and the text box
/// keeps to the chat (a row of chips wider than the chat would widen everything under it).
#[test]