Arrange: a floating window does not take a tab transfer whose target changed

A release over another document's floating window is handled before the
frame's drag cleanup. When another document became current after a tab
hover started the transfer, cleanup would have canceled it, but the
floating window still copied the artwork. The pane drop now also checks
that the transfer's target is still the current document, as cleanup does.
This commit is contained in:
dotCooCoo
2026-11-16 05:33:31 -08:00
parent 8e59bcb026
commit a7c7e2bed8
2 changed files with 37 additions and 3 deletions
+32
View File
@@ -1178,6 +1178,38 @@ fn a_tab_transfer_whose_source_changed_drops_nothing_in_a_floating_window() {
assert_eq!(app.session.active_index(), Some(2), "the window does not become current");
}
#[test]
fn a_tab_transfer_whose_target_is_no_longer_current_drops_nothing_in_a_floating_window() {
let ctx = egui::Context::default();
let mut app = floating_pair(&ctx);
app.run("file.new", json!({"width": 400, "height": 300, "name": "Third"})).unwrap();
app.run("document.activate", json!({"index": 0})).unwrap();
app.select_tool("selection");
app_frame(&mut app, &ctx, vec![]);
let tab = tab_at(&frame(&mut app, &ctx, vec![]), "Third");
grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0));
app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(tab)]);
for _ in 0..60 {
if app.session.active_index() == Some(2) {
break;
}
app_frame(&mut app, &ctx, vec![]);
}
assert_eq!(app.session.active_index(), Some(2), "the tab hover switched documents");
let drop = in_noted(&app, (1, 1), vectorcraft_geom::Point::new(200.0, 150.0));
app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop)]);
// Another document becomes current between frames, as a command from the control channel
// would make it.
app.session.set_active(0);
let target = app.session.documents()[1].doc.clone();
let target_undo = app.session.documents()[1].history.undo.len();
app_frame(&mut app, &ctx, vec![button(drop, false)]);
app_frame(&mut app, &ctx, vec![]);
assert_eq!(app.session.documents()[1].doc, target, "the floating window's document does not take the art");
assert_eq!(app.session.documents()[1].history.undo.len(), target_undo);
assert_eq!(app.session.active_index(), Some(0), "the window does not become current");
}
#[test]
fn an_os_windows_pane_is_not_a_place_to_release_art_in_the_main_windows_points() {
let _host = native_host();
+5 -3
View File
@@ -237,10 +237,12 @@ fn carried(app: &VectorcraftApp, ctx: &Context) -> Option<Carried> {
return None;
}
if let Some(art) = egui::DragAndDrop::payload::<Artwork>(ctx) {
// The same source check as [`cleanup`]: a floating window's pane takes the release before
// cleanup runs, and an edited or closed source carries nothing.
// The same checks as [`cleanup`]: a floating window's pane takes the release before cleanup
// runs, and an edited or closed source, or a target that is no longer the current
// document, carries nothing.
let source = app.session.documents().iter().any(|d| d.uid == art.origin.uid && d.same_content(&art.source));
return source.then(|| Carried { origin: art.origin.clone(), ids: art.ids.clone() });
let target = app.session.active().is_some_and(|d| d.uid == art.target);
return (source && target).then(|| Carried { origin: art.origin.clone(), ids: art.ids.clone() });
}
let origin = ctx.data(|d| d.get_temp::<Origin>(origin_id()))?;
let st = app.session.active().filter(|d| d.uid == origin.uid)?;