diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 3ecacda490..cde101a965 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -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(); diff --git a/crates/ui-egui/src/document_drag.rs b/crates/ui-egui/src/document_drag.rs index 836ea0c227..c8331e1af9 100644 --- a/crates/ui-egui/src/document_drag.rs +++ b/crates/ui-egui/src/document_drag.rs @@ -237,10 +237,12 @@ fn carried(app: &VectorcraftApp, ctx: &Context) -> Option { return None; } if let Some(art) = egui::DragAndDrop::payload::(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_id()))?; let st = app.session.active().filter(|d| d.uid == origin.uid)?;