diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index 40fe212dec..4edaa65945 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -894,12 +894,14 @@ fn show_overlays(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass, view_in } super::overlays::show(app, ui, &space, &list, &extra); // The loaded place cursor shows its current file and the files left beside the pointer, while the canvas has the - // pointer and no view tool is held. + // pointer and no view tool is held. A press that began on the canvas keeps `hover_doc` while it is dragged off it, + // so the pointer must also be over the canvas. if app.session.tool_id() == "place" && app.ui.screen_mode < 3 && app.hover_doc.is_some() && !view_tool_held(app) && let Some(at) = ui.input(|i| i.pointer.hover_pos()) + && space.view.rect.contains(at) { crate::place::cursor_overlay(app, ui, at, space.view.rect, super::overlays::BADGE_OFFSET); } diff --git a/crates/ui-egui/src/tests/place.rs b/crates/ui-egui/src/tests/place.rs index a9929312ca..45bb099d8d 100644 --- a/crates/ui-egui/src/tests/place.rs +++ b/crates/ui-egui/src/tests/place.rs @@ -493,6 +493,16 @@ fn the_loaded_place_cursor_shows_its_file_and_the_files_left_beside_the_pointer( load(&mut app, &["only.png"]); let (thumbs, counts) = shown(&mut app, Some(pointer), "only.png"); beside(&thumbs, &counts, None); + + // A press on the canvas dragged across it keeps the thumbnail, and dragged off the canvas shows nothing. + let press = egui::Event::PointerButton { pos: pointer, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }; + crate::testing::app_frame(&mut app, &ctx, raw_input(vec![egui::Event::PointerMoved(pointer), press], vec![], vec![])); + let (thumbs, _) = shown(&mut app, Some(pointer + vec2(10.0, 10.0)), "only.png"); + assert_eq!(thumbs.len(), 1, "dragged on the canvas: {thumbs:?}"); + let outside = egui::pos2(pointer.x, canvas.min.y - 4.0); + assert!(outside.y > 0.0, "{canvas:?} leaves room above it"); + let (thumbs, counts) = shown(&mut app, Some(outside), "only.png"); + assert!(thumbs.is_empty() && counts.is_empty(), "dragged off the canvas: {thumbs:?} {counts:?}"); } /// A tiny SVG document.