From c367a8e9914d7555e288adfdcb02975e62b0ce26 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 00:14:41 -0800 Subject: [PATCH 1/6] Arrange: a Selection drag released in another document's tiled pane drops the artwork there MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Under Window › Arrange › Tile, a Selection move dragged from the current pane and released over another document's pane copies the artwork into that document with edit.dropSelection, with no tab hover first. The pane becomes the current window, and the grab point lands under the pointer in that pane's own zoom and rotation. A release over another view of the source document moves the artwork with object.move, and Alt copies it. The source move is rolled back before the canvas sees the release, also when the pointer enters the pane and the button goes up in one frame. Artwork carried to a document through its tab can also be released in a third document's pane. A release over a pane's rulers or scroll bars, or after Escape, changes neither document, and a press in another pane with no artwork carried still only makes its document current. Dragging into a floating document window and the tab overflow menu are not covered. Docs: development.md, target-app-parity.md, gaps.md, roadmap.md, ui-parity.md. --- crates/ui-egui/src/canvas.rs | 2 +- crates/ui-egui/src/canvas/drag.rs | 10 +- crates/ui-egui/src/canvas/panes.rs | 47 ++++- crates/ui-egui/src/canvas/panes/tests.rs | 216 +++++++++++++++++++++++ crates/ui-egui/src/document_drag.rs | 91 +++++++++- docs/development.md | 16 +- docs/gaps.md | 6 +- docs/roadmap.md | 6 +- docs/target-app-parity.md | 6 +- docs/ui-parity.md | 8 +- 10 files changed, 387 insertions(+), 21 deletions(-) diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index 847b60fd87..b914d1f626 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -42,7 +42,7 @@ pub use cursor::{HOVER_STILL_SECS, STILL_SECS, ViewKey}; use cursor::{cursor_icon, hover_cursor, hover_wait, still_wait}; use drag::drag_id; pub use drag::{apply_requests, dispatch, mods}; -pub(crate) use drag::{end_document_drag, pose_on_page, release_art_in_window, release_over_panel}; +pub(crate) use drag::{art_out, end_art_move, end_document_drag, pose_on_page, release_art_in_window, release_over_panel}; #[cfg(test)] use drag::{frame_moves, tool_drag_doc_id, tool_drag_moved, tool_frame_moves, tool_press_doc_id}; pub use fill::Fill; diff --git a/crates/ui-egui/src/canvas/drag.rs b/crates/ui-egui/src/canvas/drag.rs index cb01cf71d4..38be9651c7 100644 --- a/crates/ui-egui/src/canvas/drag.rs +++ b/crates/ui-egui/src/canvas/drag.rs @@ -29,6 +29,11 @@ pub(crate) fn end_document_drag(ctx: &egui::Context) { }); } +/// Whether a Selection tool move has left the canvas ([`drag_art_out`]) and still waits there. +pub(crate) fn art_out(ctx: &egui::Context) -> bool { + matches!(ctx.data(|d| d.get_temp::(drag_id())), Some(Drag::Art)) +} + /// Temp-memory key for the active canvas drag state. pub(super) fn drag_id() -> egui::Id { egui::Id::unique("canvas-drag") @@ -355,8 +360,9 @@ pub(crate) fn release_art_in_window(app: &mut VectorcraftApp, ctx: &egui::Contex } } -/// Roll back the art move dragged off the canvas; a panel takes the art instead. -fn end_art_move(app: &mut VectorcraftApp, ctx: &egui::Context) { +/// Roll back the art move dragged off the canvas, and end the canvas's drag; a panel or another +/// window's tiled pane takes the art instead. +pub(crate) fn end_art_move(app: &mut VectorcraftApp, ctx: &egui::Context) { // With no document open there is nothing to roll back; the tool still gets its mouse-up. let _ = app.session.cancel_interaction(); let view = app.view_info(); diff --git a/crates/ui-egui/src/canvas/panes.rs b/crates/ui-egui/src/canvas/panes.rs index bf070af076..dd2fec382f 100644 --- a/crates/ui-egui/src/canvas/panes.rs +++ b/crates/ui-egui/src/canvas/panes.rs @@ -1,8 +1,9 @@ //! Window › Arrange › Tile: every open document in a pane of its own, edge to edge in the document //! area. The current document's pane is the canvas ([`super::show`]). Each other pane draws its //! document from a render of its own, with its artboards, guides and selected objects, and a press -//! in it makes its document the current one. Each view Window › New Window opened has a pane of -//! its own ([`crate::doc_windows`]). +//! in it makes its document the current one. A Selection drag released in it drops the dragged +//! artwork into its document ([`crate::document_drag::drop_on_pane`]). Each view Window › New +//! Window opened has a pane of its own ([`crate::doc_windows`]). use std::collections::HashMap; use std::sync::Arc; @@ -243,12 +244,18 @@ pub(crate) fn tiled_area(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { let areas: Vec<(Win, egui::Rect)> = cells.iter().map(|(w, cell)| (*w, view_rects(app, *cell, ppp).1)).collect(); let unfitted = refit_resized(app, &areas); let mut activate = None; + let (mut cursor, mut dropped) = (None, None); // The other panes first, so that what the canvas draws past its pane (the Contextual Task Bar) // stays over them. - for (w, cell) in cells.iter().copied().filter(|(w, _)| Some(*w) != active) { + for ((w, cell), (_, area)) in cells.iter().copied().zip(areas.iter().copied()).filter(|((w, _), _)| Some(*w) != active) { if pane(app, ui, w, cell) { activate = Some(w); } + match artwork_over(app, ui, w, area) { + Some(Over::Held(c)) => cursor = Some(c), + Some(Over::Released(at, carried)) => dropped = Some((w, at, carried)), + None => {} + } ui.painter().rect_stroke(cell, 0.0, Stroke::new(1.0, t.border), StrokeKind::Inside); } if let Some((_, cell)) = cells.iter().copied().find(|(w, _)| Some(*w) == active) { @@ -256,6 +263,10 @@ pub(crate) fn tiled_area(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { super::show(app, &mut canvas); ui.painter().rect_stroke(cell, 0.0, Stroke::new(1.5, t.accent), StrokeKind::Inside); } + // After the canvas, which sets the cursor of the drag it holds. + if let Some(c) = cursor { + ui.ctx().set_cursor_icon(c); + } // Note the fits this frame made, for `refit_resized`. for ((w, area), was_unfitted) in areas.iter().zip(unfitted) { if let (true, Some(v), Some(s)) = (was_unfitted, crate::doc_windows::view(app, *w).filter(|v| v.fitted).copied(), slot(app, *w)) { @@ -263,12 +274,40 @@ pub(crate) fn tiled_area(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { } } app.canvas.panes.last = cells; - if let Some(w) = activate { + if let Some((w, at, carried)) = dropped { + crate::document_drag::drop_on_pane(app, ui.ctx(), w, at, carried); + } else if let Some(w) = activate { crate::doc_windows::show_window(app, w); } true } +/// A Selection drag's artwork over another window's tiled pane. +enum Over { + /// Held there: the cursor that shows whether a release moves or copies it. + Held(egui::CursorIcon), + /// Released there, at a document point in the pane's own view. + Released(Point, crate::document_drag::Carried), +} + +/// A Selection drag's artwork over `area`, the part of window `w`'s pane inside its rulers and +/// scroll bars, where no panel or floating window is over the pointer. A release there takes the +/// artwork before the canvas sees the release ([`crate::document_drag::take_for_pane`]). +fn artwork_over(app: &mut VectorcraftApp, ui: &Ui, w: Win, area: egui::Rect) -> Option { + let (uid, _) = slot(app, w)?; + let p = ui.input(|i| i.pointer.interact_pos())?; + if !area.contains(p) || ui.ctx().layer_id_at(p).is_some_and(|l| l != ui.layer_id()) { + return None; + } + let cursor = crate::document_drag::pane_cursor(app, ui.ctx(), uid)?; + if !ui.input(|i| i.pointer.primary_released()) { + return Some(Over::Held(cursor)); + } + let v = crate::doc_windows::view(app, w).copied()?; + let at = Xf::at(area, &v, ui.ctx().zoom_factor()).to_doc(p); + Some(Over::Released(at, crate::document_drag::take_for_pane(app, ui.ctx())?)) +} + /// Window `w`'s [`Slot`]. fn slot(app: &VectorcraftApp, (i, n): Win) -> Option { app.session.documents().get(i).map(|d| (d.uid, n)) diff --git a/crates/ui-egui/src/canvas/panes/tests.rs b/crates/ui-egui/src/canvas/panes/tests.rs index 34611fd0d7..85301cd22b 100644 --- a/crates/ui-egui/src/canvas/panes/tests.rs +++ b/crates/ui-egui/src/canvas/panes/tests.rs @@ -165,6 +165,222 @@ fn a_press_in_another_pane_makes_its_document_current_without_drawing() { assert!(app.session.documents()[1..].iter().all(|d| d.doc.art_bounds().is_none())); } +/// One headless frame at `time` seconds as the app runs it: a Selection move released off the +/// canvas ends first ([`crate::canvas::release_over_panel`]), then the tabs and the panes draw. +fn timed_frame(app: &mut VectorcraftApp, ctx: &egui::Context, time: Option, events: Vec) -> egui::FullOutput { + let raw = egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0))), + max_texture_side: Some(8192), + time, + events, + ..Default::default() + }; + let mut out = ctx.run_ui(raw, |ui| { + crate::canvas::release_over_panel(app, ui.ctx()); + app.canvas_area(ui); + }); + out.textures_delta.clear(); + out +} + +/// [`timed_frame`] without a time. → the cursor. +fn app_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) -> egui::CursorIcon { + timed_frame(app, ctx, None, events).platform_output.cursor_icon +} + +/// Two 400 × 300 pt documents tiled side by side: the first, current, holds a selected 100 pt +/// square at 50, 50 and the second a 50 pt square at 300, 230. The Selection tool is chosen. +fn tiled_pair() -> (VectorcraftApp, egui::Context) { + let mut app = app_with(0); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 100, "height": 100})).unwrap(); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("shape.rectangle", json!({"x": 300, "y": 230, "width": 50, "height": 50})).unwrap(); + app.run("document.activate", json!({"index": 0})).unwrap(); + app.select_tool("selection"); + app.ui.task_bar = false; + app.run("window.arrange.tile", json!({})).unwrap(); + let ctx = egui::Context::default(); + app_frame(&mut app, &ctx, vec![]); + app_frame(&mut app, &ctx, vec![]); + (app, ctx) +} + +/// Press on document point `at` on the canvas and move the pointer 20 × 10 points, still on the +/// canvas: the Selection tool moves the art under it. +fn grab(app: &mut VectorcraftApp, ctx: &egui::Context, at: Point) { + let p = Xf::at(app.canvas_rect.unwrap(), app.view().unwrap(), 1.0).to_screen(at); + app_frame(app, ctx, vec![egui::Event::PointerMoved(p), button(p, true)]); + app_frame(app, ctx, vec![egui::Event::PointerMoved(p + vec2(20.0, 10.0))]); + assert!(app.session.in_interaction(), "the Selection tool moves the art"); +} + +/// Window `w`'s pane: the screen point that shows document point `at` in it, and the pane. +fn in_pane(app: &VectorcraftApp, ctx: &egui::Context, w: Win, at: Point) -> (Pos2, egui::Rect) { + let (_, cell) = app.canvas.panes.last.iter().copied().find(|(o, _)| *o == w).unwrap(); + let area = view_rects(app, cell, ctx.pixels_per_point()).1; + (Xf::at(area, crate::doc_windows::view(app, w).unwrap(), 1.0).to_screen(at), cell) +} + +/// How many objects document `i`'s first layer holds. +fn objects(app: &VectorcraftApp, i: usize) -> usize { + app.session.documents()[i].doc.layers[0].children().map_or(0, Vec::len) +} + +/// The bounds of the one object selected in the current document. +fn selected_bounds(app: &VectorcraftApp) -> Rect { + let st = app.session.active().unwrap(); + assert_eq!(st.selection.objects.len(), 1, "one object is selected"); + st.doc.node(st.selection.objects[0]).unwrap().geometric_bounds().unwrap() +} + +#[test] +fn a_selection_drag_released_in_another_documents_pane_copies_the_art_there() { + let (mut app, ctx) = tiled_pair(); + // The target's view differs from the source's: the grab point still lands under the pointer. + app.views[1].zoom *= 0.6; + app.views[1].rotation = 30.0; + app_frame(&mut app, &ctx, vec![]); + let source = app.session.documents()[0].doc.clone(); + let source_undo = app.session.documents()[0].history.undo.len(); + let target = app.session.documents()[1].doc.clone(); + let target_undo = app.session.documents()[1].history.undo.len(); + let clipboard = app.session.clipboard.clone(); + grab(&mut app, &ctx, Point::new(100.0, 100.0)); + let (drop, _) = in_pane(&app, &ctx, (1, 1), Point::new(170.0, 120.0)); + // The release comes in the first frame the pointer is over the pane. + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop), button(drop, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(1), "the pane's document is the current one"); + let placed = selected_bounds(&app); + assert!((placed.center().x - 170.0).abs() < 0.01 && (placed.center().y - 120.0).abs() < 0.01, "{placed:?}"); + assert_eq!(app.session.documents()[1].history.undo.len(), target_undo + 1, "one step to undo"); + assert_eq!(app.session.documents()[0].doc, source, "the source keeps its art where it was"); + assert_eq!(app.session.documents()[0].history.undo.len(), source_undo); + assert_eq!(app.session.clipboard, clipboard, "the drag leaves the clipboard alone"); + assert!(!app.session.tool_busy()); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(app.session.documents()[1].doc, target); + app.run("edit.redo", json!({})).unwrap(); + assert_eq!(app.session.documents()[1].history.undo.len(), target_undo + 1); +} + +#[test] +fn art_held_over_another_pane_shows_a_copy_and_drags_back_the_other_way() { + let (mut app, ctx) = tiled_pair(); + grab(&mut app, &ctx, Point::new(100.0, 100.0)); + let (over, _) = in_pane(&app, &ctx, (1, 1), Point::new(200.0, 150.0)); + let cursor = app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(over)]); + assert_eq!(cursor, egui::CursorIcon::Copy, "over another document's pane the art is copied"); + assert_eq!(app.session.active_index(), Some(0), "holding the art over a pane does not switch documents"); + let (drop, _) = in_pane(&app, &ctx, (1, 1), Point::new(120.0, 90.0)); + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop)]); + app_frame(&mut app, &ctx, vec![button(drop, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(1)); + assert_eq!(objects(&app, 1), 2, "the copy joins the target's square"); + // From the target, now the canvas, back into the first document's pane. + app_frame(&mut app, &ctx, vec![]); + grab(&mut app, &ctx, Point::new(325.0, 255.0)); + let (back, _) = in_pane(&app, &ctx, (0, 1), Point::new(300.0, 200.0)); + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(back), button(back, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(0)); + let placed = selected_bounds(&app); + assert!((placed.center().x - 300.0).abs() < 0.01 && (placed.center().y - 200.0).abs() < 0.01, "{placed:?}"); + assert_eq!(objects(&app, 0), 2); +} + +#[test] +fn a_selection_drag_into_another_view_of_its_document_moves_the_art() { + let (mut app, ctx) = tiled_pair(); + app.run("window.newWindow", json!({})).unwrap(); + app.run("window.arrange.tile", json!({})).unwrap(); + app_frame(&mut app, &ctx, vec![]); + app_frame(&mut app, &ctx, vec![]); + let current = crate::doc_windows::current(&app).unwrap(); + let other = app.canvas.panes.last.iter().map(|(w, _)| *w).find(|w| w.0 == 0 && *w != current).unwrap(); + let undo = app.session.documents()[0].history.undo.len(); + let target = app.session.documents()[1].doc.clone(); + grab(&mut app, &ctx, Point::new(100.0, 100.0)); + let (drop, _) = in_pane(&app, &ctx, other, Point::new(250.0, 200.0)); + let cursor = app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop)]); + assert_eq!(cursor, egui::CursorIcon::Move, "another view of the same document moves the art"); + app_frame(&mut app, &ctx, vec![button(drop, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(crate::doc_windows::current(&app), Some(other), "the pane's view is the current window"); + assert_eq!(objects(&app, 0), 1, "the square moved, not copied"); + let moved = selected_bounds(&app); + assert!((moved.center().x - 250.0).abs() < 0.01 && (moved.center().y - 200.0).abs() < 0.01, "{moved:?}"); + assert_eq!(app.session.documents()[0].history.undo.len(), undo + 1); + assert_eq!(app.session.documents()[1].doc, target, "the other document is untouched"); +} + +#[test] +fn art_carried_through_a_tab_drops_into_a_third_documents_pane() { + let (mut app, ctx) = tiled_pair(); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("document.activate", json!({"index": 0})).unwrap(); + app.run("window.arrange.tile", json!({})).unwrap(); + let source = app.session.documents()[0].doc.clone(); + let third = app.session.documents()[2].doc.clone(); + let titles = |out: egui::FullOutput| -> Vec { + let mut t: Vec<_> = out + .shapes + .iter() + .filter_map(|s| match &s.shape { + Shape::Text(t) if t.galley.text().contains(" @ ") => Some(egui::Rect::from_min_size(t.pos, t.galley.size())), + _ => None, + }) + .collect(); + t.sort_by(|a, b| a.left().total_cmp(&b.left())); + t + }; + timed_frame(&mut app, &ctx, Some(0.0), vec![]); + let tabs = titles(timed_frame(&mut app, &ctx, Some(0.01), vec![])); + assert_eq!(tabs.len(), 3); + let p = Xf::at(app.canvas_rect.unwrap(), app.view().unwrap(), 1.0).to_screen(Point::new(100.0, 100.0)); + timed_frame(&mut app, &ctx, Some(0.05), vec![egui::Event::PointerMoved(p), button(p, true)]); + timed_frame(&mut app, &ctx, Some(0.1), vec![egui::Event::PointerMoved(p + vec2(20.0, 10.0))]); + timed_frame(&mut app, &ctx, Some(0.2), vec![egui::Event::PointerMoved(tabs[2].center())]); + timed_frame(&mut app, &ctx, Some(0.25), vec![]); + timed_frame(&mut app, &ctx, Some(0.8), vec![]); + assert_eq!(app.session.active_index(), Some(2), "holding the art over the third tab makes that document current"); + timed_frame(&mut app, &ctx, Some(0.85), vec![]); + let (drop, _) = in_pane(&app, &ctx, (1, 1), Point::new(150.0, 100.0)); + timed_frame(&mut app, &ctx, Some(0.9), vec![egui::Event::PointerMoved(drop)]); + timed_frame(&mut app, &ctx, Some(1.0), vec![button(drop, false)]); + timed_frame(&mut app, &ctx, Some(1.1), vec![]); + assert_eq!(app.session.active_index(), Some(1), "the pane's document is the current one"); + assert_eq!(objects(&app, 1), 2, "the copy joins the second document's square"); + let placed = selected_bounds(&app); + assert!((placed.center().x - 150.0).abs() < 0.01 && (placed.center().y - 100.0).abs() < 0.01, "{placed:?}"); + assert_eq!(app.session.documents()[0].doc, source); + assert_eq!(app.session.documents()[2].doc, third, "the document the tab showed is untouched"); +} + +#[test] +fn a_drag_released_off_a_panes_art_area_or_after_escape_changes_nothing() { + for (case, escape) in [("scroll bar", false), ("art area after Escape", true)] { + let (mut app, ctx) = tiled_pair(); + let docs: Vec<_> = app.session.documents().iter().map(|d| (d.doc.clone(), d.history.undo.len())).collect(); + grab(&mut app, &ctx, Point::new(100.0, 100.0)); + let (inside, cell) = in_pane(&app, &ctx, (1, 1), Point::new(200.0, 150.0)); + let at = if escape { inside } else { pos2(cell.right() - 2.0, cell.center().y) }; + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]); + if escape { + let key = egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + app_frame(&mut app, &ctx, vec![key]); + } + app_frame(&mut app, &ctx, vec![button(at, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(0), "{case}: the source stays current"); + let after: Vec<_> = app.session.documents().iter().map(|d| (d.doc.clone(), d.history.undo.len())).collect(); + assert!(after == docs, "{case}: neither document changes"); + assert!(!app.session.in_interaction(), "{case}: the move ended"); + } +} + #[test] fn consolidate_all_windows_shows_one_document_again() { let mut app = app_with(2); diff --git a/crates/ui-egui/src/document_drag.rs b/crates/ui-egui/src/document_drag.rs index b44d09b5c3..7be4cfa1c4 100644 --- a/crates/ui-egui/src/document_drag.rs +++ b/crates/ui-egui/src/document_drag.rs @@ -1,4 +1,5 @@ -//! A selection dragged across document tabs remains editable and leaves its source intact. +//! A selection dragged across document tabs, or into another document's tiled pane, remains +//! editable and leaves its source intact. use std::sync::Arc; @@ -90,13 +91,15 @@ pub(crate) fn cleanup(app: &VectorcraftApp, ctx: &Context) { || i.multi_touch().is_some() || i.events.iter().any(|e| matches!(e, egui::Event::Touch { phase: egui::TouchPhase::Cancel, .. })) }); - let outside_release = - ctx.input(|i| i.pointer.primary_released() && !app.canvas_rect.is_some_and(|r| i.pointer.interact_pos().is_some_and(|p| r.contains(p)))); + // The canvas and the other windows' tiled panes take a release ([`drop_on_pane`]). + let target = |p: egui::Pos2| app.canvas_rect.is_some_and(|r| r.contains(p)) || app.canvas.panes.last.iter().any(|(_, r)| r.contains(p)); + let outside_release = ctx.input(|i| i.pointer.primary_released() && !i.pointer.interact_pos().is_some_and(target)); if !valid || cancel || outside_release || app.ui.dialog.is_some() { egui::DragAndDrop::clear_payload(ctx); } } - if !ctx.input(|i| i.pointer.primary_down()) { + // The source and grab point last through the release, for the pane it is released over. + if !ctx.input(|i| i.pointer.primary_down() || i.pointer.primary_released()) { ctx.data_mut(|d| { d.remove::(origin_id()); d.remove::(hover_id()); @@ -210,3 +213,83 @@ pub(crate) fn drop_on_canvas(app: &mut VectorcraftApp, resp: &Response, xf: &can } } } + +/// The artwork a Selection drag carries out of its canvas, taken by another window's tiled pane +/// ([`take_for_pane`]): its source and grab point, and the objects that travel. +pub(crate) struct Carried { + origin: Origin, + ids: Vec, +} + +/// The artwork a Selection drag carries: the transfer a tab hover started, or a Selection move of +/// the current document that left its canvas. The canvas hands that move over as a panel drag +/// ([`widgets::PanelDrag::Art`]) the frame after the pointer leaves, and Escape drops that; until +/// then the move under way is the drag. Either way the objects the move started with travel, not +/// an Alt-drag's preview copies. +fn carried(app: &VectorcraftApp, ctx: &Context) -> Option { + if ctx.input(|i| !i.focused || i.multi_touch().is_some() || i.key_pressed(egui::Key::Escape)) || app.ui.dialog.is_some() { + return None; + } + if let Some(art) = egui::DragAndDrop::payload::(ctx) { + return Some(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)?; + let ids = match egui::DragAndDrop::payload::(ctx).as_deref() { + Some(widgets::PanelDrag::Art(ids)) => ids.clone(), + Some(_) => return None, + None if canvas::art_out(ctx) => return None, + None => st.interaction.as_ref().filter(|i| i.label == "Move" || i.label == "Copy")?.selection.objects.clone(), + }; + (!ids.is_empty()).then_some(Carried { origin, ids }) +} + +/// Over the tiled pane of a window of document `uid`, while a Selection drag carries artwork: the +/// cursor that shows a move for another view of the source document without Alt, and a copy +/// otherwise. None when no artwork is carried. +pub(crate) fn pane_cursor(app: &VectorcraftApp, ctx: &Context, uid: u64) -> Option { + let c = carried(app, ctx)?; + let copy = ctx.input(|i| i.modifiers.alt); + Some(if c.origin.uid == uid && !copy { egui::CursorIcon::Move } else { egui::CursorIcon::Copy }) +} + +/// A release over another window's tiled pane takes the carried artwork: the drag ends, and a +/// move still under way on the canvas goes back to where it started, before the canvas sees the +/// release ([`canvas::end_art_move`]). +pub(crate) fn take_for_pane(app: &mut VectorcraftApp, ctx: &Context) -> Option { + let c = carried(app, ctx)?; + let moving = !egui::DragAndDrop::has_payload_of_type::(ctx) && app.session.in_interaction(); + egui::DragAndDrop::clear_payload(ctx); + ctx.data_mut(|d| d.remove::(origin_id())); + if moving { + canvas::end_art_move(app, ctx); + } + Some(c) +} + +/// The artwork `c` taken over window `w`'s tiled pane ([`take_for_pane`]), released at document +/// point `at` in that pane's view: `w` becomes the current window, and the artwork lands with its +/// grab point at `at`. Into another document it is copied (`edit.dropSelection`), and the source +/// stays as it was; in another view of the source document it moves, and Alt copies it +/// (`object.move`). When the command fails, the window that was current stays current and the +/// status bar shows the error. +pub(crate) fn drop_on_pane(app: &mut VectorcraftApp, ctx: &Context, w: crate::doc_windows::Win, at: Point, c: Carried) { + let Carried { origin, ids } = c; + let Some(uid) = app.session.documents().get(w.0).map(|d| d.uid) else { return }; + let before = crate::doc_windows::current(app); + app.ui.home = None; + crate::doc_windows::show_window(app, w); + let result = if uid == origin.uid { + let copy = ctx.input(|i| i.modifiers.alt); + app.run("object.move", json!({"ids": ids, "dx": at.x - origin.grab.x, "dy": at.y - origin.grab.y, "copy": copy})) + } else { + app.run("edit.dropSelection", json!({"sourceDocument": origin.uid, "ids": ids, "grab": [origin.grab.x, origin.grab.y], "at": [at.x, at.y]})) + }; + if let Err(e) = result { + if let Some(b) = before { + crate::doc_windows::show_window(app, b); + } + app.status(e); + } + ctx.request_repaint(); +} diff --git a/docs/development.md b/docs/development.md index 64b66678b5..8cf61cb285 100644 --- a/docs/development.md +++ b/docs/development.md @@ -497,7 +497,21 @@ to the source tab resumes a move (Alt copies). Escape or release outside the can Changing the source revision or unexpectedly changing/closing the destination cancels a stale transfer; focus loss, touch cancellation and multitouch cancel too. Moving tabs under a stationary pointer does not activate further tabs until the pointer moves. The close icon does not activate a tab during a drag. Overflow-menu hover activation and -cross-window dragging remain outside this change. +dragging into a floating document window remain outside this change. + +Under Window › Arrange › Tile, a Selection move released over another document's pane copies the +artwork into that document through `edit.dropSelection`, with no tab hover first. The pane becomes +the current window, the grab point lands under the pointer in that pane's own zoom and rotation, and +the source move is rolled back, including when the pointer enters the pane and the button is released +in the same frame. A release over another view of the source document (Window › New Window) moves the +artwork there with `object.move`, and Alt copies it. While the artwork is held over a pane, the cursor +shows a copy or a move. A release over a pane's rulers or scroll bars, or after Escape, changes +neither document. A press in another pane with no artwork carried still only makes its document +current. Page 14 of [the help page](https://help.adobe.com/archive/en_US/illustrator/cs4/illustrator_cs4_help.pdf) +describes documents arranged side by side, with items dragged from one document into another. +Evidence: the `canvas::panes` tests drive real pointer frames from the current pane into another +document's pane, back the other way, into another view, through a tab into a third document's pane, +and off a pane's art area. The cited regressions assert the internal clipboard; they do not exercise the native system-clipboard adapter. Tab activation resets the Selection tool through `Session::set_active`; gesture regressions verify it is idle after switching, dropping diff --git a/docs/gaps.md b/docs/gaps.md index eda7bb21dd..e9b658dc89 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -875,8 +875,10 @@ sampling coexistence. Scores and estimates unchanged. See [development.md](devel Selection drags activate another visible document tab after 400 ms, then copy editable artwork on canvas release with the original grab point. Source and clipboard preservation, resource rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression -coverage (`tests_document_drag`, `tests_clipboard`). Overflow-menu and cross-window drag remain -separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over +another document's pane copies the artwork into that document as well, and a release over another +view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a +floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Pathfinder › Trap (2026-10-23) diff --git a/docs/roadmap.md b/docs/roadmap.md index fae091f647..bb78bbff9b 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -201,8 +201,10 @@ sampling coexistence. Scores and estimates unchanged. See [development.md](devel Selection drags activate another visible document tab after 400 ms, then copy editable artwork on canvas release with the original grab point. Source and clipboard preservation, resource rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression -coverage (`tests_document_drag`, `tests_clipboard`). Overflow-menu and cross-window drag remain -separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over +another document's pane copies the artwork into that document as well, and a release over another +view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a +floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Revision history diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 0782bacab9..79ac4cbc89 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2266,8 +2266,10 @@ sampling coexistence. Scores and estimates unchanged. See [development.md](devel Selection drags activate another visible document tab after 400 ms, then copy editable artwork on canvas release with the original grab point. Source and clipboard preservation, resource rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression -coverage (`tests_document_drag`, `tests_clipboard`). Overflow-menu and cross-window drag remain -separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over +another document's pane copies the artwork into that document as well, and a release over another +view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a +floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Gradient dither (2026-10-22) diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 8e06948b33..50927bf211 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -384,7 +384,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Interaction | Status | Evidence | |---|---|---| | Ordinary Save refused by filesystem permissions/read-only storage offers Save As | focused UI regressions passed; native acceptance pending | #6146; `io::tests_read_only_save`; same name/format suggested; unchanged format keeps options, changed format opens its Save options; Documents folder, UID-bound continuation; cancellation and automation isolation | -| Selection artwork drag hovers a visible document tab to activate it, then drops editable artwork on its canvas | done | `tests_document_drag`, `edit.dropSelection`, lossless resource and one-step Undo regressions; overflow and cross-window drag remain separate | +| Selection artwork drag hovers a visible document tab to activate it, then drops editable artwork on its canvas | done | `tests_document_drag`, `edit.dropSelection`, lossless resource and one-step Undo regressions; a release over another document's tiled pane copies it there too (`canvas::panes` tests); overflow-menu and floating-window drag remain separate | | A document tab dragged along the tab strip moves its document; a line marks where it goes, the current document and every document's view stay as they were, and a drag off the strip still floats it | done | #5663, [public source](https://helpx.adobe.com/illustrator/using/customizing-workspace.html); `document.move`; `tests::tab_reorder`, `chrome::tests` (drop index with floating and view tabs), `engine` `tests::document_move` | | A middle-click on a document tab or its × closes it as the × does; closing a modified document's last view asks to save first (VectorCraft addition, as in PhotoCraft) | done | #6506; `chrome::tests::a_middle_click_on_a_tab_closes_it_as_the_close_box_does`; not scored | | Panels hidden by Tab or Shift+Tab show for a while when the pointer rests on the left or right edge of the window, over the canvas, and hide again when it moves away; Tab shows them for good | done | Part of #5661; `window.panels.peek` ([Workspace basics](https://web.archive.org/web/2014/https://helpx.adobe.com/illustrator/using/workspace-basics.html), "Hide or show all panels"); VectorCraft's own choices: the 6 pt band and the 0.3 s delays, only the docked panels on that side show (floating panels, Tools and the Control bar stay hidden), and nothing shows in Presentation Mode; `panel_docking::tests::resting_on_the_right_edge_shows_the_hidden_panels_over_the_canvas_until_the_pointer_leaves` and the tests after it | @@ -541,8 +541,10 @@ sampling coexistence. Scores and estimates unchanged. See [development.md](devel Selection drags activate another visible document tab after 400 ms, then copy editable artwork on canvas release with the original grab point. Source and clipboard preservation, resource rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression -coverage (`tests_document_drag`, `tests_clipboard`). Overflow-menu and cross-window drag remain -separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over +another document's pane copies the artwork into that document as well, and a release over another +view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a +floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Live Paint Bucket From b429b00851f3fadebf4606622bf02fae63fb110f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 03:28:50 -0800 Subject: [PATCH 2/6] Arrange: a Selection drag released in another document's floating window drops the artwork there MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With Window › Arrange › Float in Window, a Selection move released over the art area of another document's floating window copies the artwork into that document with edit.dropSelection, as a release over a tiled pane does. The window becomes the current one, and the grab point lands under the pointer in that window's own zoom and rotation. While the current document floats, a release over the pane the main window draws copies the artwork into the main window's document. A floating window with another view of the source document takes a move, and Alt copies. The release is taken at the start of the frame, before any canvas sees it, so a release in the first frame over a window still drops the artwork, and the source move is rolled back first. A release on a window's title bar, rulers or scroll bars, or after Escape, changes neither document. This covers floating windows drawn inside the main window (the web, Wayland and a control channel). A floating window that is an OS window of its own does not take the artwork yet. Docs: development.md, target-app-parity.md, gaps.md, roadmap.md, ui-parity.md. --- crates/ui-egui/src/app.rs | 17 +- crates/ui-egui/src/canvas.rs | 2 +- crates/ui-egui/src/canvas/drag.rs | 3 + crates/ui-egui/src/canvas/panes.rs | 46 +++++ crates/ui-egui/src/doc_windows.rs | 30 +++- crates/ui-egui/src/doc_windows/tests.rs | 217 ++++++++++++++++++++++++ crates/ui-egui/src/document_drag.rs | 4 +- docs/development.md | 17 +- docs/gaps.md | 6 +- docs/roadmap.md | 6 +- docs/target-app-parity.md | 6 +- docs/ui-parity.md | 8 +- 12 files changed, 336 insertions(+), 26 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index f708d0f454..ceb8f3cdeb 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -495,12 +495,14 @@ impl VectorcraftApp { /// The canvas panel's body: the document tabs, the canvas (a pane for each document while /// Window › Arrange › Tile is on) and the isolation bar over it. While the current document is - /// in a floating window, the tab strip's document draws as a pane. + /// in a floating window, the tab strip's document draws as a pane, which a Selection drag's + /// artwork can be released in ([`canvas::note_drop`]). pub(crate) fn canvas_area(&mut self, ui: &mut egui::Ui) { let t = theme::Tokens::get(ui.ctx()); // Tools may already occupy the left side of this panel. ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, t.pasteboard); self.canvas.windows.strip = None; + self.canvas.windows.drops.clear(); if self.ui.screen_mode < 3 { chrome::doc_tabs(self, ui); } @@ -509,10 +511,15 @@ impl VectorcraftApp { if !canvas::tiled_area(self, ui) { if floats { let rect = ui.available_rect_before_wrap(); - if let Some(w) = crate::doc_windows::tab_window(self) - && canvas::pane(self, ui, w, rect) - { - crate::doc_windows::show_window(self, w); + if let Some(w) = crate::doc_windows::tab_window(self) { + let pressed = canvas::pane(self, ui, w, rect); + // A drag from a current window that is an OS window ends in that window. + if !crate::doc_windows::native(self, ui.ctx()) { + canvas::note_drop(self, ui, w, rect); + } + if pressed { + crate::doc_windows::show_window(self, w); + } } } else { canvas::show(self, ui); diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index b914d1f626..607f9c15ea 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -65,7 +65,7 @@ pub use overlays::SharedPaths; use overlays::selected_anchor; use overlays::{HandleLook, blend_widgets_overlay, draw_inside_overlay, draw_overlays, hover_highlight, ime_geometry, selection_overlay}; pub use panes::Panes; -pub(crate) use panes::{consolidate, pane, tile, tiled_area}; +pub(crate) use panes::{consolidate, note_drop, noted_cursor, pane, release_on_noted, tile, tiled_area}; use raster::{changed_pixels, frame_ppp, pixel_region, upload}; pub(crate) use raster::{color_image, color_image_owned, render_job}; pub use selection_marks::SelectionMarks; diff --git a/crates/ui-egui/src/canvas/drag.rs b/crates/ui-egui/src/canvas/drag.rs index 38be9651c7..68f06c70cc 100644 --- a/crates/ui-egui/src/canvas/drag.rs +++ b/crates/ui-egui/src/canvas/drag.rs @@ -325,6 +325,9 @@ pub(super) fn drag_art_out(app: &VectorcraftApp, ui: &Ui, resp: &egui::Response, /// panel that takes the art ([`widgets::PanelDrag::Art`]) takes it where it was, and no move is /// left open (#2826). The art stays where it last moved while the pointer is over the panel. pub(crate) fn release_over_panel(app: &mut VectorcraftApp, ctx: &egui::Context) { + // A floating window's pane, or the main window's while the current window floats, takes the + // art first. + super::release_on_noted(app, ctx); crate::document_drag::cleanup(app, ctx); let art = matches!(ctx.data(|d| d.get_temp::(drag_id())), Some(Drag::Art)); // Over a floating panel's own OS window the pointer is gone from this window, and the release diff --git a/crates/ui-egui/src/canvas/panes.rs b/crates/ui-egui/src/canvas/panes.rs index dd2fec382f..473bc53839 100644 --- a/crates/ui-egui/src/canvas/panes.rs +++ b/crates/ui-egui/src/canvas/panes.rs @@ -308,6 +308,52 @@ fn artwork_over(app: &mut VectorcraftApp, ui: &Ui, w: Win, area: egui::Rect) -> Some(Over::Released(at, crate::document_drag::take_for_pane(app, ui.ctx())?)) } +/// Note window `w`'s pane, drawn in `cell` of `ui` outside Tile (a floating window inside the main +/// window, or the main window while the current window floats), as a place a Selection drag's +/// artwork can be released in ([`release_on_noted`]): the part inside its rulers and scroll bars. +pub(crate) fn note_drop(app: &mut VectorcraftApp, ui: &Ui, w: Win, cell: egui::Rect) { + let Some(s) = slot(app, w) else { return }; + let area = view_rects(app, cell, ui.ctx().pixels_per_point()).1; + app.canvas.windows.drops.push((s, area, ui.layer_id())); +} + +/// The noted pane ([`note_drop`]) at `p`, where no panel or other window is over it: its window +/// and its art area. +fn noted_at(app: &VectorcraftApp, ctx: &egui::Context, p: egui::Pos2) -> Option<(Win, egui::Rect)> { + let top = ctx.layer_id_at(p); + let (s, area, _) = app.canvas.windows.drops.iter().rev().find(|(_, area, layer)| area.contains(p) && top.is_none_or(|l| l == *layer))?; + let w = crate::doc_windows::windows(app).into_iter().find(|w| slot(app, *w) == Some(*s))?; + Some((w, *area)) +} + +/// A Selection drag's artwork released over a pane the last frame noted ([`note_drop`]) drops into +/// its document ([`crate::document_drag::drop_on_pane`]), at the document point under the pointer +/// in that pane's own view. Runs at the start of a frame, before any canvas sees the release. +pub(crate) fn release_on_noted(app: &mut VectorcraftApp, ctx: &egui::Context) { + if app.canvas.windows.drops.is_empty() || !ctx.input(|i| i.pointer.primary_released()) { + return; + } + let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return }; + let Some((w, area)) = noted_at(app, ctx, p) else { return }; + let Some(v) = crate::doc_windows::view(app, w).copied() else { return }; + let at = Xf::at(area, &v, ctx.zoom_factor()).to_doc(p); + if let Some(carried) = crate::document_drag::take_for_pane(app, ctx) { + crate::document_drag::drop_on_pane(app, ctx, w, at, carried); + } +} + +/// While a Selection drag's artwork is held over a pane this frame noted ([`note_drop`]), the cursor +/// shows whether a release there moves or copies it ([`crate::document_drag::pane_cursor`]). +pub(crate) fn noted_cursor(app: &VectorcraftApp, ctx: &egui::Context) { + let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return }; + if let Some((w, _)) = noted_at(app, ctx, p) + && let Some((uid, _)) = slot(app, w) + && let Some(c) = crate::document_drag::pane_cursor(app, ctx, uid) + { + ctx.set_cursor_icon(c); + } +} + /// Window `w`'s [`Slot`]. fn slot(app: &VectorcraftApp, (i, n): Win) -> Option { app.session.documents().get(i).map(|d| (d.uid, n)) diff --git a/crates/ui-egui/src/doc_windows.rs b/crates/ui-egui/src/doc_windows.rs index 619c563e44..ba324558d3 100644 --- a/crates/ui-egui/src/doc_windows.rs +++ b/crates/ui-egui/src/doc_windows.rs @@ -4,7 +4,9 @@ //! the main window, it is a window inside the app's window, as floating panels are //! ([`crate::panel_docking`]). The current document's window holds the canvas //! ([`crate::canvas::show`]); each other window draws its document as a Tile pane does -//! ([`crate::canvas::pane`]), and a press in it makes its document the current one. +//! ([`crate::canvas::pane`]), and a press in it makes its document the current one. In a window +//! inside the app's window, a Selection drag released over that pane drops the dragged artwork into +//! its document ([`crate::canvas::release_on_noted`]); an OS window's pane does not take it. //! //! A document tab dragged off the tab strip floats its document in a window under the pointer, //! and a document window dragged onto the tab strip by its title bar (an OS window by the tab at @@ -95,6 +97,10 @@ pub struct Windows { known: Vec, /// The documents' views beyond the one each shows ([`views`]). pub(crate) views: Views, + /// The panes the last frame drew outside Tile that a Selection drag's artwork can be released + /// in ([`crate::canvas::note_drop`]): each window's view ([`views::key`]), the part of its pane + /// inside its rulers and scroll bars in the main window's points, and the layer it drew in. + pub(crate) drops: Vec<((u64, u32), egui::Rect, egui::LayerId)>, } impl Windows { @@ -325,7 +331,7 @@ pub(crate) fn dock_all(app: &mut VectorcraftApp) { /// floats panels by the same rule), and no control channel is attached. With a control channel the /// windows stay inside the main window, where `ui.click`, `ui.drag` and `ui.screenshot` reach them /// and `canvasRect` is in the main window's coordinates. -fn native(app: &VectorcraftApp, ctx: &egui::Context) -> bool { +pub(crate) fn native(app: &VectorcraftApp, ctx: &egui::Context) -> bool { if ctx.embed_viewports() || app.control_rx.is_some() { return false; } @@ -469,6 +475,8 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { activate = Some(win); } } + // After every canvas, which sets the cursor of the drag it holds. + crate::canvas::noted_cursor(app, ctx); // The tab strip a dragged window would go back under shows where it lands. if let Some(strip) = app.canvas.windows.strip.filter(|_| over_strip) { let t = crate::theme::Tokens::get(ctx); @@ -499,9 +507,10 @@ pub(crate) fn show(app: &mut VectorcraftApp, ctx: &egui::Context) { /// Window `win`'s body in `ui`: the canvas for the current window, else (and while `blocked` by a /// modal) a pane. The view fits the body again when the body changed size since `fit` and the view -/// has not moved. → whether a press in the pane asks for its window to become the current one, the -/// body's rect and the fit after this frame. -fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, (win, blocked): (Win, bool), fit: Option) -> (bool, egui::Rect, Option) { +/// has not moved. With `drops`, a pane drawn while no modal blocks it is noted as a place a Selection +/// drag's artwork can be released in ([`crate::canvas::note_drop`]). → whether a press in the pane +/// asks for its window to become the current one, the body's rect and the fit after this frame. +fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, (win, blocked): (Win, bool), fit: Option, drops: bool) -> (bool, egui::Rect, Option) { let t = crate::theme::Tokens::get(ui.ctx()); let rect = ui.available_rect_before_wrap(); ui.painter().rect_filled(rect, 0.0, t.pasteboard); @@ -517,7 +526,11 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, (win, blocked): (Win, bool) crate::canvas::show(app, ui); false } else { - crate::canvas::pane(app, ui, win, rect) + let pressed = crate::canvas::pane(app, ui, win, rect); + if drops && !blocked { + crate::canvas::note_drop(app, ui, win, rect); + } + pressed }; ui.advance_cursor_after_rect(rect); let fit = match view(app, win) { @@ -564,7 +577,8 @@ fn os_window(app: &mut VectorcraftApp, ctx: &egui::Context, w: &DocWindow, (win, } let tab = crate::chrome::window_tab(app, ui, win); let (over_strip, dock) = if blocked { (false, false) } else { drag_tab(app, ui, ((w.uid, w.view), origin), &tab, strip) }; - let (pressed, rect, fit) = body(app, ui, (win, blocked), w.fit); + // The OS window's points are not the main window's: its pane takes no artwork. + let (pressed, rect, fit) = body(app, ui, (win, blocked), w.fit, false); let activate = pressed || (!blocked && (tab.clicked() || tab.drag_started())); // Keys the window's widgets left over run the main window's shortcuts and tool keys, as a // floating panel's do. @@ -649,7 +663,7 @@ fn app_window(app: &mut VectorcraftApp, ctx: &egui::Context, w: &DocWindow, (win .frame(frame) .open(&mut open) .show(ctx, |ui| { - let (pressed, r, f) = body(app, ui, (win, blocked), fit); + let (pressed, r, f) = body(app, ui, (win, blocked), fit, true); (activate, rect, fit) = (pressed, Some(r), f); }); // A press on its title bar or edges, which brings the window to the front, also makes its diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 64a693a09b..0b4babec61 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -925,3 +925,220 @@ fn switching_views_targets_the_artboard_the_view_shows() { show_window(&mut app, (0, 2)); assert_eq!(app.session.tool_options()["active"], json!(1)); } + +/// One headless frame as the app runs it: a Selection move released off the canvas ends first +/// ([`crate::canvas::release_over_panel`]), then the tabs and the canvas or panes, then the floating +/// document windows. → the cursor. +fn app_frame(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) -> egui::CursorIcon { + let raw = egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0))), + max_texture_side: Some(8192), + events, + ..Default::default() + }; + let mut out = ctx.run_ui(raw, |ui| { + crate::canvas::release_over_panel(app, ui.ctx()); + app.canvas_area(ui); + show(app, ui.ctx()); + }); + out.textures_delta.clear(); + out.platform_output.cursor_icon +} + +/// Two 400 × 300 pt documents on `ctx`: the first, current under its tab, holds a 50 pt square at +/// 300, 230, and the second, in a floating window, a 50 pt square at 50, 50. The Selection tool is +/// chosen. +fn floating_pair(ctx: &egui::Context) -> VectorcraftApp { + let mut app = app_with(0); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("shape.rectangle", json!({"x": 300, "y": 230, "width": 50, "height": 50})).unwrap(); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("shape.rectangle", json!({"x": 50, "y": 50, "width": 50, "height": 50})).unwrap(); + app.run("window.arrange.floatInWindow", json!({})).unwrap(); + app.run("document.activate", json!({"index": 0})).unwrap(); + app.select_tool("selection"); + app.ui.task_bar = false; + app_frame(&mut app, ctx, vec![]); + app_frame(&mut app, ctx, vec![]); + app +} + +/// Press on document point `at` on the canvas, clear of document 1's window when it floats, and +/// move the pointer 10 × 5 points: the Selection tool moves the art under it. +fn grab(app: &mut VectorcraftApp, ctx: &egui::Context, at: vectorcraft_geom::Point) { + let p = crate::canvas::Xf::at(app.canvas_rect.unwrap(), app.view().unwrap(), 1.0).to_screen(at); + if app.session.documents().len() > 1 && app.session.active_index() != Some(1) && is_floating(app, 1) { + assert!(!window_of(app, ctx, 1).contains(p), "the art is clear of the floating window"); + } + app_frame(app, ctx, vec![egui::Event::PointerMoved(p), button(p, true)]); + app_frame(app, ctx, vec![egui::Event::PointerMoved(p + vec2(10.0, 5.0))]); + assert!(app.session.in_interaction(), "the Selection tool moves the art"); +} + +/// The screen point that shows document point `at` in window `w`'s pane, which the last frame noted +/// as a place to release artwork in. +fn in_noted(app: &VectorcraftApp, w: Win, at: vectorcraft_geom::Point) -> Pos2 { + let k = key(app, w).unwrap(); + let (_, area, _) = app.canvas.windows.drops.iter().find(|(s, _, _)| *s == k).unwrap(); + crate::canvas::Xf::at(*area, view(app, w).unwrap(), 1.0).to_screen(at) +} + +/// How many objects document `i`'s first layer holds. +fn objects(app: &VectorcraftApp, i: usize) -> usize { + app.session.documents()[i].doc.layers[0].children().map_or(0, Vec::len) +} + +/// The center of the one object selected in the current document. +fn selected_center(app: &VectorcraftApp) -> vectorcraft_geom::Point { + let st = app.session.active().unwrap(); + assert_eq!(st.selection.objects.len(), 1, "one object is selected"); + st.doc.node(st.selection.objects[0]).unwrap().geometric_bounds().unwrap().center() +} + +#[test] +fn a_selection_drag_released_in_another_documents_floating_window_copies_the_art_there() { + let ctx = egui::Context::default(); + let mut app = floating_pair(&ctx); + // The target's view differs from the source's: the grab point still lands under the pointer. + let v = view_mut(&mut app, (1, 1)).unwrap(); + v.zoom *= 0.6; + v.rotation = 30.0; + app_frame(&mut app, &ctx, vec![]); + let source = app.session.documents()[0].doc.clone(); + let source_undo = app.session.documents()[0].history.undo.len(); + let target = app.session.documents()[1].doc.clone(); + let target_undo = app.session.documents()[1].history.undo.len(); + let clipboard = app.session.clipboard.clone(); + grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0)); + let drop = in_noted(&app, (1, 1), vectorcraft_geom::Point::new(170.0, 120.0)); + let cursor = app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop)]); + assert_eq!(cursor, egui::CursorIcon::Copy, "over another document's window the art is copied"); + assert_eq!(app.session.active_index(), Some(0), "holding the art over the window does not switch documents"); + app_frame(&mut app, &ctx, vec![button(drop, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(1), "the window's document is the current one"); + assert_eq!(objects(&app, 1), 2, "the copy joins the target's square"); + let placed = selected_center(&app); + assert!((placed.x - 170.0).abs() < 0.01 && (placed.y - 120.0).abs() < 0.01, "{placed:?}"); + assert_eq!(app.session.documents()[1].history.undo.len(), target_undo + 1, "one step to undo"); + assert_eq!(app.session.documents()[0].doc, source, "the source keeps its art where it was"); + assert_eq!(app.session.documents()[0].history.undo.len(), source_undo); + assert_eq!(app.session.clipboard, clipboard, "the drag leaves the clipboard alone"); + assert!(!app.session.tool_busy()); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(app.session.documents()[1].doc, target); +} + +#[test] +fn a_release_in_the_first_frame_over_a_floating_window_still_copies_the_art() { + let ctx = egui::Context::default(); + let mut app = floating_pair(&ctx); + let source = app.session.documents()[0].doc.clone(); + grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0)); + let drop = in_noted(&app, (1, 1), vectorcraft_geom::Point::new(200.0, 150.0)); + // The canvas has not handed the move over yet: the pane takes it before the canvas sees the + // release. + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop), button(drop, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(1)); + assert_eq!(objects(&app, 1), 2); + let placed = selected_center(&app); + assert!((placed.x - 200.0).abs() < 0.01 && (placed.y - 150.0).abs() < 0.01, "{placed:?}"); + assert_eq!(app.session.documents()[0].doc, source); +} + +#[test] +fn art_dragged_from_a_floating_window_drops_into_the_main_windows_document() { + let ctx = egui::Context::default(); + let mut app = floating_pair(&ctx); + show_window(&mut app, (1, 1)); + app_frame(&mut app, &ctx, vec![]); + app_frame(&mut app, &ctx, vec![]); + assert!(current_floats(&app), "the floating window holds the canvas"); + let target = app.session.documents()[1].doc.clone(); + grab(&mut app, &ctx, vectorcraft_geom::Point::new(75.0, 75.0)); + // The main window draws document 0 as a pane; this point is clear of the floating window. + let at = vectorcraft_geom::Point::new(360.0, 40.0); + let drop = in_noted(&app, (0, 1), at); + assert!(!window_of(&app, &ctx, 1).contains(drop), "{drop:?}"); + let cursor = app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop)]); + assert_eq!(cursor, egui::CursorIcon::Copy); + app_frame(&mut app, &ctx, vec![button(drop, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(0), "the main window's document is the current one"); + assert_eq!(objects(&app, 0), 2); + let placed = selected_center(&app); + assert!((placed.x - at.x).abs() < 0.01 && (placed.y - at.y).abs() < 0.01, "{placed:?}"); + assert_eq!(app.session.documents()[1].doc, target, "the source in the floating window is untouched"); +} + +#[test] +fn a_selection_drag_into_a_floating_view_of_its_document_moves_the_art() { + let ctx = egui::Context::default(); + let mut app = app_with(0); + app.run("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.run("shape.rectangle", json!({"x": 300, "y": 230, "width": 50, "height": 50})).unwrap(); + app.run("window.newWindow", json!({})).unwrap(); + app.run("window.arrange.floatInWindow", json!({})).unwrap(); + show_window(&mut app, (0, 1)); + app.select_tool("selection"); + app.ui.task_bar = false; + app_frame(&mut app, &ctx, vec![]); + app_frame(&mut app, &ctx, vec![]); + assert!(floats(&app, (0, 2)) && current(&app) == Some((0, 1))); + let undo = app.session.documents()[0].history.undo.len(); + grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0)); + let drop = in_noted(&app, (0, 2), vectorcraft_geom::Point::new(150.0, 100.0)); + let cursor = app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop)]); + assert_eq!(cursor, egui::CursorIcon::Move, "another view of the same document moves the art"); + app_frame(&mut app, &ctx, vec![button(drop, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(current(&app), Some((0, 2)), "the floating view is the current window"); + assert_eq!(objects(&app, 0), 1, "the square moved, not copied"); + let moved = selected_center(&app); + assert!((moved.x - 150.0).abs() < 0.01 && (moved.y - 100.0).abs() < 0.01, "{moved:?}"); + assert_eq!(app.session.documents()[0].history.undo.len(), undo + 1); +} + +#[test] +fn a_drag_released_on_a_floating_windows_title_bar_or_after_escape_changes_nothing() { + for (case, escape) in [("title bar", false), ("art area after Escape", true)] { + let ctx = egui::Context::default(); + let mut app = floating_pair(&ctx); + let docs: Vec<_> = app.session.documents().iter().map(|d| (d.doc.clone(), d.history.undo.len())).collect(); + grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0)); + let (window, body) = (window_of(&app, &ctx, 1), body_of(&app, 1)); + let at = if escape { + in_noted(&app, (1, 1), vectorcraft_geom::Point::new(200.0, 150.0)) + } else { + pos2(window.left() + 60.0, (window.top() + body.top()) / 2.0) + }; + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(at)]); + if escape { + let key = egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + app_frame(&mut app, &ctx, vec![key]); + } + app_frame(&mut app, &ctx, vec![button(at, false)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(0), "{case}: the source stays current"); + let after: Vec<_> = app.session.documents().iter().map(|d| (d.doc.clone(), d.history.undo.len())).collect(); + assert!(after == docs, "{case}: neither document changes"); + assert!(!app.session.in_interaction(), "{case}: the move ended"); + } +} + +#[test] +fn an_os_windows_pane_is_not_a_place_to_release_art_in_the_main_windows_points() { + let _host = native_host(); + let ctx = egui::Context::default(); + ctx.set_embed_viewports(false); + if !native(&app_with(0), &ctx) { + // Wayland: the windows are inside the main window. + return; + } + let mut app = floating_pair(&ctx); + assert!(app.canvas.windows.drops.is_empty(), "the other document's OS window is not noted"); + show_window(&mut app, (1, 1)); + app_frame(&mut app, &ctx, vec![]); + assert!(app.canvas.windows.drops.is_empty(), "nor is the main window's pane while an OS window holds the canvas"); +} diff --git a/crates/ui-egui/src/document_drag.rs b/crates/ui-egui/src/document_drag.rs index 7be4cfa1c4..90595bd06e 100644 --- a/crates/ui-egui/src/document_drag.rs +++ b/crates/ui-egui/src/document_drag.rs @@ -1,5 +1,5 @@ -//! A selection dragged across document tabs, or into another document's tiled pane, remains -//! editable and leaves its source intact. +//! A selection dragged across document tabs, or into another document's tiled pane or floating +//! window, remains editable and leaves its source intact. use std::sync::Arc; diff --git a/docs/development.md b/docs/development.md index 8cf61cb285..37971d93e7 100644 --- a/docs/development.md +++ b/docs/development.md @@ -497,7 +497,7 @@ to the source tab resumes a move (Alt copies). Escape or release outside the can Changing the source revision or unexpectedly changing/closing the destination cancels a stale transfer; focus loss, touch cancellation and multitouch cancel too. Moving tabs under a stationary pointer does not activate further tabs until the pointer moves. The close icon does not activate a tab during a drag. Overflow-menu hover activation and -dragging into a floating document window remain outside this change. +dragging into a floating document window that is an OS window of its own remain outside this change. Under Window › Arrange › Tile, a Selection move released over another document's pane copies the artwork into that document through `edit.dropSelection`, with no tab hover first. The pane becomes @@ -512,6 +512,21 @@ describes documents arranged side by side, with items dragged from one document Evidence: the `canvas::panes` tests drive real pointer frames from the current pane into another document's pane, back the other way, into another view, through a tab into a third document's pane, and off a pane's art area. + +The same release works for documents in floating windows (Window › Arrange › Float in Window) where +those windows are drawn inside the main window: on the web, on Wayland and with a control channel +attached. A Selection move released over the art area of another document's floating window copies +the artwork into that document, and one released over the pane the main window draws while the +current document floats copies it into the main window's document. A floating window that shows +another view of the source document takes a move, and Alt copies. The release is taken at the start +of the frame, before any canvas sees it, so a release in the first frame over a window still drops the +artwork. A release on a window's title bar, rulers or scroll bars, or after Escape, changes neither +document. A floating window that is an OS window of its own, the default on Windows, macOS and X11, +does not take the artwork: its pointer positions are in that window's points, not the main window's. +Evidence: the `doc_windows` tests drive real pointer frames from the main window's canvas into a +floating window (rotated and zoomed, and in the frame the pointer arrives), from a floating window +into the main window's pane, into a floating view of the same document, and onto a title bar and +after Escape, and check that no OS window's pane is noted. The cited regressions assert the internal clipboard; they do not exercise the native system-clipboard adapter. Tab activation resets the Selection tool through `Session::set_active`; gesture regressions verify it is idle after switching, dropping diff --git a/docs/gaps.md b/docs/gaps.md index e9b658dc89..967fca7ce9 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -877,8 +877,10 @@ on canvas release with the original grab point. Source and clipboard preservatio rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over another document's pane copies the artwork into that document as well, and a release over another -view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a -floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +view of the source document moves it (`canvas::panes` tests). A release over a floating document +window drawn inside the main window, or over the main window's pane while the current document +floats, does the same (`doc_windows` tests); a floating window that is an OS window of its own does +not take the artwork yet. Overflow-menu drag remains separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Pathfinder › Trap (2026-10-23) diff --git a/docs/roadmap.md b/docs/roadmap.md index bb78bbff9b..c1afb4fbd2 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -203,8 +203,10 @@ on canvas release with the original grab point. Source and clipboard preservatio rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over another document's pane copies the artwork into that document as well, and a release over another -view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a -floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +view of the source document moves it (`canvas::panes` tests). A release over a floating document +window drawn inside the main window, or over the main window's pane while the current document +floats, does the same (`doc_windows` tests); a floating window that is an OS window of its own does +not take the artwork yet. Overflow-menu drag remains separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Revision history diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 79ac4cbc89..1a283e3b5a 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2268,8 +2268,10 @@ on canvas release with the original grab point. Source and clipboard preservatio rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over another document's pane copies the artwork into that document as well, and a release over another -view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a -floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +view of the source document moves it (`canvas::panes` tests). A release over a floating document +window drawn inside the main window, or over the main window's pane while the current document +floats, does the same (`doc_windows` tests); a floating window that is an OS window of its own does +not take the artwork yet. Overflow-menu drag remains separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Gradient dither (2026-10-22) diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 50927bf211..5a67a5098e 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -384,7 +384,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po | Interaction | Status | Evidence | |---|---|---| | Ordinary Save refused by filesystem permissions/read-only storage offers Save As | focused UI regressions passed; native acceptance pending | #6146; `io::tests_read_only_save`; same name/format suggested; unchanged format keeps options, changed format opens its Save options; Documents folder, UID-bound continuation; cancellation and automation isolation | -| Selection artwork drag hovers a visible document tab to activate it, then drops editable artwork on its canvas | done | `tests_document_drag`, `edit.dropSelection`, lossless resource and one-step Undo regressions; a release over another document's tiled pane copies it there too (`canvas::panes` tests); overflow-menu and floating-window drag remain separate | +| Selection artwork drag hovers a visible document tab to activate it, then drops editable artwork on its canvas | done | `tests_document_drag`, `edit.dropSelection`, lossless resource and one-step Undo regressions; a release over another document's tiled pane copies it there too (`canvas::panes` tests), and so does a release over a floating window drawn inside the main window (`doc_windows` tests); overflow-menu drag and floating OS windows remain separate | | A document tab dragged along the tab strip moves its document; a line marks where it goes, the current document and every document's view stay as they were, and a drag off the strip still floats it | done | #5663, [public source](https://helpx.adobe.com/illustrator/using/customizing-workspace.html); `document.move`; `tests::tab_reorder`, `chrome::tests` (drop index with floating and view tabs), `engine` `tests::document_move` | | A middle-click on a document tab or its × closes it as the × does; closing a modified document's last view asks to save first (VectorCraft addition, as in PhotoCraft) | done | #6506; `chrome::tests::a_middle_click_on_a_tab_closes_it_as_the_close_box_does`; not scored | | Panels hidden by Tab or Shift+Tab show for a while when the pointer rests on the left or right edge of the window, over the canvas, and hide again when it moves away; Tab shows them for good | done | Part of #5661; `window.panels.peek` ([Workspace basics](https://web.archive.org/web/2014/https://helpx.adobe.com/illustrator/using/workspace-basics.html), "Hide or show all panels"); VectorCraft's own choices: the 6 pt band and the 0.3 s delays, only the docked panels on that side show (floating panels, Tools and the Control bar stay hidden), and nothing shows in Presentation Mode; `panel_docking::tests::resting_on_the_right_edge_shows_the_hidden_panels_over_the_canvas_until_the_pointer_leaves` and the tests after it | @@ -543,8 +543,10 @@ on canvas release with the original grab point. Source and clipboard preservatio rendering, swatch conflicts, cancellation, rotated/zoomed views and target Undo/Redo have regression coverage (`tests_document_drag`, `tests_clipboard`). Under Window › Arrange › Tile, a release over another document's pane copies the artwork into that document as well, and a release over another -view of the source document moves it (`canvas::panes` tests). Overflow-menu drag and drag into a -floating document window remain separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). +view of the source document moves it (`canvas::panes` tests). A release over a floating document +window drawn inside the main window, or over the main window's pane while the current document +floats, does the same (`doc_windows` tests); a floating window that is an OS window of its own does +not take the artwork yet. Overflow-menu drag remains separate. Scores and hours unchanged. [Behavior and command details](development.md#drag-artwork-between-document-tabs-2026-10-22). ## Live Paint Bucket From 96c0076d8d805c71c0a8da2afd5653283241001d Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 03:45:21 -0800 Subject: [PATCH 3/6] Arrange: a floating window does not take a tab transfer whose source changed A release over another document's floating window is handled before the frame's drag cleanup, so a tab transfer whose source document was edited or closed since the last frame could still be copied into the window. The pane drop now checks that the source document still holds the content the drag started with, as the canvas drop does. --- crates/ui-egui/src/doc_windows/tests.rs | 34 +++++++++++++++++++++++++ crates/ui-egui/src/document_drag.rs | 5 +++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 0b4babec61..02c764f5f9 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -1127,6 +1127,40 @@ fn a_drag_released_on_a_floating_windows_title_bar_or_after_escape_changes_nothi } } +#[test] +fn a_tab_transfer_whose_source_changed_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)); + // Held over the third document's tab, the drag becomes a transfer to that document. + 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)]); + // The source changes between frames, as a command from the control channel would change it. + app.session.set_active(0); + app.session.execute("shape.ellipse", &json!({"x": 20, "y": 20, "width": 30, "height": 30})).unwrap(); + app.session.set_active(2); + 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 changed art"); + assert_eq!(app.session.documents()[1].history.undo.len(), target_undo); + assert_eq!(app.session.active_index(), Some(2), "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 90595bd06e..a975732972 100644 --- a/crates/ui-egui/src/document_drag.rs +++ b/crates/ui-egui/src/document_drag.rs @@ -231,7 +231,10 @@ fn carried(app: &VectorcraftApp, ctx: &Context) -> Option { return None; } if let Some(art) = egui::DragAndDrop::payload::(ctx) { - return Some(Carried { origin: art.origin.clone(), ids: art.ids.clone() }); + // 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. + 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 origin = ctx.data(|d| d.get_temp::(origin_id()))?; let st = app.session.active().filter(|d| d.uid == origin.uid)?; From 7b04069d1e764fdea4f9741313db4bdefeb7fc00 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 04:47:18 -0800 Subject: [PATCH 4/6] Arrange: a drop uses the position and Alt of the button release A frame can carry the primary button's release and then a pointer move or a change of modifiers. The tiled pane, the floating window and the canvas read the pointer position and Alt at the end of the frame, so a move after the release could change where the artwork landed or which pane took it, and Alt let go in the same frame moved the originals instead of copying them. The drop now takes its position and Alt from the release event, as the canvas already does for its own drags (canvas/input.rs release_pos). --- crates/ui-egui/src/canvas/panes.rs | 8 +++--- crates/ui-egui/src/canvas/panes/tests.rs | 32 +++++++++++++++++++++++ crates/ui-egui/src/doc_windows/tests.rs | 17 ++++++++++++ crates/ui-egui/src/document_drag.rs | 27 ++++++++++++++++--- crates/ui-egui/src/tests/document_drag.rs | 25 ++++++++++++++++++ 5 files changed, 102 insertions(+), 7 deletions(-) diff --git a/crates/ui-egui/src/canvas/panes.rs b/crates/ui-egui/src/canvas/panes.rs index 473bc53839..e6e16ad271 100644 --- a/crates/ui-egui/src/canvas/panes.rs +++ b/crates/ui-egui/src/canvas/panes.rs @@ -295,7 +295,7 @@ enum Over { /// artwork before the canvas sees the release ([`crate::document_drag::take_for_pane`]). fn artwork_over(app: &mut VectorcraftApp, ui: &Ui, w: Win, area: egui::Rect) -> Option { let (uid, _) = slot(app, w)?; - let p = ui.input(|i| i.pointer.interact_pos())?; + let p = ui.input(crate::document_drag::released_at)?; if !area.contains(p) || ui.ctx().layer_id_at(p).is_some_and(|l| l != ui.layer_id()) { return None; } @@ -327,13 +327,13 @@ fn noted_at(app: &VectorcraftApp, ctx: &egui::Context, p: egui::Pos2) -> Option< } /// A Selection drag's artwork released over a pane the last frame noted ([`note_drop`]) drops into -/// its document ([`crate::document_drag::drop_on_pane`]), at the document point under the pointer -/// in that pane's own view. Runs at the start of a frame, before any canvas sees the release. +/// its document ([`crate::document_drag::drop_on_pane`]), at the document point where the button +/// went up, in that pane's own view. Runs at the start of a frame, before any canvas sees the release. pub(crate) fn release_on_noted(app: &mut VectorcraftApp, ctx: &egui::Context) { if app.canvas.windows.drops.is_empty() || !ctx.input(|i| i.pointer.primary_released()) { return; } - let Some(p) = ctx.input(|i| i.pointer.interact_pos()) else { return }; + let Some(p) = ctx.input(crate::document_drag::released_at) else { return }; let Some((w, area)) = noted_at(app, ctx, p) else { return }; let Some(v) = crate::doc_windows::view(app, w).copied() else { return }; let at = Xf::at(area, &v, ctx.zoom_factor()).to_doc(p); diff --git a/crates/ui-egui/src/canvas/panes/tests.rs b/crates/ui-egui/src/canvas/panes/tests.rs index 85301cd22b..03c0ce7bed 100644 --- a/crates/ui-egui/src/canvas/panes/tests.rs +++ b/crates/ui-egui/src/canvas/panes/tests.rs @@ -316,6 +316,38 @@ fn a_selection_drag_into_another_view_of_its_document_moves_the_art() { assert_eq!(app.session.documents()[1].doc, target, "the other document is untouched"); } +#[test] +fn a_pane_drop_lands_where_the_button_went_up_and_copies_when_alt_was_held_then() { + // A pointer move later in the frame of the release does not move the drop. + let (mut app, ctx) = tiled_pair(); + grab(&mut app, &ctx, Point::new(100.0, 100.0)); + let (drop, _) = in_pane(&app, &ctx, (1, 1), Point::new(170.0, 120.0)); + let (later, _) = in_pane(&app, &ctx, (1, 1), Point::new(80.0, 60.0)); + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop), button(drop, false), egui::Event::PointerMoved(later)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(1)); + let placed = selected_bounds(&app); + assert!((placed.center().x - 170.0).abs() < 0.01 && (placed.center().y - 120.0).abs() < 0.01, "{placed:?}"); + // Alt held at the release and let go later in that frame copies into another view of the source. + let (mut app, ctx) = tiled_pair(); + app.run("window.newWindow", json!({})).unwrap(); + app.run("window.arrange.tile", json!({})).unwrap(); + app_frame(&mut app, &ctx, vec![]); + app_frame(&mut app, &ctx, vec![]); + let current = crate::doc_windows::current(&app).unwrap(); + let other = app.canvas.panes.last.iter().map(|(w, _)| *w).find(|w| w.0 == 0 && *w != current).unwrap(); + grab(&mut app, &ctx, Point::new(100.0, 100.0)); + let (drop, _) = in_pane(&app, &ctx, other, Point::new(250.0, 200.0)); + let alt = egui::Modifiers::ALT; + let cursor = app_frame(&mut app, &ctx, vec![egui::Event::ModifiersChanged(alt), egui::Event::PointerMoved(drop)]); + assert_eq!(cursor, egui::CursorIcon::Copy, "Alt shows a copy"); + let up = egui::Event::PointerButton { pos: drop, button: egui::PointerButton::Primary, pressed: false, modifiers: alt }; + app_frame(&mut app, &ctx, vec![up, egui::Event::ModifiersChanged(egui::Modifiers::NONE)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(crate::doc_windows::current(&app), Some(other)); + assert_eq!(objects(&app, 0), 2, "the square was copied, not moved"); +} + #[test] fn art_carried_through_a_tab_drops_into_a_third_documents_pane() { let (mut app, ctx) = tiled_pair(); diff --git a/crates/ui-egui/src/doc_windows/tests.rs b/crates/ui-egui/src/doc_windows/tests.rs index 02c764f5f9..3ecacda490 100644 --- a/crates/ui-egui/src/doc_windows/tests.rs +++ b/crates/ui-egui/src/doc_windows/tests.rs @@ -1047,6 +1047,23 @@ fn a_release_in_the_first_frame_over_a_floating_window_still_copies_the_art() { assert_eq!(app.session.documents()[0].doc, source); } +#[test] +fn a_floating_window_drop_lands_where_the_button_went_up() { + let ctx = egui::Context::default(); + let mut app = floating_pair(&ctx); + grab(&mut app, &ctx, vectorcraft_geom::Point::new(325.0, 255.0)); + let drop = in_noted(&app, (1, 1), vectorcraft_geom::Point::new(200.0, 150.0)); + let later = in_noted(&app, (1, 1), vectorcraft_geom::Point::new(120.0, 220.0)); + app_frame(&mut app, &ctx, vec![egui::Event::PointerMoved(drop)]); + // A pointer move later in the frame of the release does not move the drop. + app_frame(&mut app, &ctx, vec![button(drop, false), egui::Event::PointerMoved(later)]); + app_frame(&mut app, &ctx, vec![]); + assert_eq!(app.session.active_index(), Some(1)); + assert_eq!(objects(&app, 1), 2); + let placed = selected_center(&app); + assert!((placed.x - 200.0).abs() < 0.01 && (placed.y - 150.0).abs() < 0.01, "{placed:?}"); +} + #[test] fn art_dragged_from_a_floating_window_drops_into_the_main_windows_document() { let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/document_drag.rs b/crates/ui-egui/src/document_drag.rs index a975732972..53a509e265 100644 --- a/crates/ui-egui/src/document_drag.rs +++ b/crates/ui-egui/src/document_drag.rs @@ -93,7 +93,7 @@ pub(crate) fn cleanup(app: &VectorcraftApp, ctx: &Context) { }); // The canvas and the other windows' tiled panes take a release ([`drop_on_pane`]). let target = |p: egui::Pos2| app.canvas_rect.is_some_and(|r| r.contains(p)) || app.canvas.panes.last.iter().any(|(_, r)| r.contains(p)); - let outside_release = ctx.input(|i| i.pointer.primary_released() && !i.pointer.interact_pos().is_some_and(target)); + let outside_release = ctx.input(|i| i.pointer.primary_released() && !released_at(i).is_some_and(target)); if !valid || cancel || outside_release || app.ui.dialog.is_some() { egui::DragAndDrop::clear_payload(ctx); } @@ -197,10 +197,11 @@ pub(crate) fn drop_on_canvas(app: &mut VectorcraftApp, resp: &Response, xf: &can resp.ctx.set_cursor_icon(if same && !copy { egui::CursorIcon::Move } else { egui::CursorIcon::Copy }); } if let Some(art) = resp.dnd_release_payload::() - && let Some(at) = resp.ctx.input(|i| i.pointer.interact_pos()).map(|p| xf.to_doc(p)) + && let Some(at) = resp.ctx.input(released_at).map(|p| xf.to_doc(p)) { let result = if same { // Back in the source tab, resume the ordinary move (Alt copies). + let copy = release_alt(&resp.ctx); app.run("object.move", json!({"ids": art.ids, "dx": at.x-art.origin.grab.x, "dy": at.y-art.origin.grab.y, "copy": copy})) } else { app.run( @@ -283,7 +284,7 @@ pub(crate) fn drop_on_pane(app: &mut VectorcraftApp, ctx: &Context, w: crate::do app.ui.home = None; crate::doc_windows::show_window(app, w); let result = if uid == origin.uid { - let copy = ctx.input(|i| i.modifiers.alt); + let copy = release_alt(ctx); app.run("object.move", json!({"ids": ids, "dx": at.x - origin.grab.x, "dy": at.y - origin.grab.y, "copy": copy})) } else { app.run("edit.dropSelection", json!({"sourceDocument": origin.uid, "ids": ids, "grab": [origin.grab.x, origin.grab.y], "at": [at.x, at.y]})) @@ -296,3 +297,23 @@ pub(crate) fn drop_on_pane(app: &mut VectorcraftApp, ctx: &Context, w: crate::do } ctx.request_repaint(); } + +/// The primary button's release in this frame: where it went up, and the modifiers held then. +fn primary_release(i: &egui::InputState) -> Option<(egui::Pos2, egui::Modifiers)> { + i.events.iter().find_map(|e| match e { + egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed: false, modifiers } => Some((*pos, *modifiers)), + _ => None, + }) +} + +/// Where the primary button went up in this frame, else where the pointer is. A pointer move later +/// in the frame of the release does not change where the artwork is released. +pub(crate) fn released_at(i: &egui::InputState) -> Option { + primary_release(i).map(|(p, _)| p).or(i.pointer.interact_pos()) +} + +/// Whether Alt was held when the primary button went up in this frame, else whether it is held now. +/// Alt let go later in the frame of the release still copies. +fn release_alt(ctx: &Context) -> bool { + ctx.input(|i| primary_release(i).map_or(i.modifiers.alt, |(_, m)| m.alt)) +} diff --git a/crates/ui-egui/src/tests/document_drag.rs b/crates/ui-egui/src/tests/document_drag.rs index cefe441020..dba75e316c 100644 --- a/crates/ui-egui/src/tests/document_drag.rs +++ b/crates/ui-egui/src/tests/document_drag.rs @@ -291,6 +291,31 @@ fn hovering_back_to_source_resumes_move_instead_of_copying() { assert!((bounds.x0 - 150.0).abs() < 0.001 && (bounds.y0 - 150.0).abs() < 0.001, "{bounds:?}"); } +/// Verify that a drop back in the source tab lands where the button went up and copies when Alt was +/// held then, though the pointer moves and Alt is let go later in the frame of the release. +#[test] +fn a_drop_back_in_the_source_uses_the_release_position_and_alt() { + let (mut app, ctx, _, tabs) = drag_fixture(); + frame(&mut app, &ctx, 0.2, vec![Event::PointerMoved(tabs[1].center())]); + frame(&mut app, &ctx, 0.25, vec![]); + frame(&mut app, &ctx, 0.8, vec![]); + frame(&mut app, &ctx, 0.9, vec![Event::PointerMoved(tabs[0].center())]); + frame(&mut app, &ctx, 1.4, vec![]); + assert_eq!(app.session.active_index(), Some(0)); + let xf = canvas::Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()); + let drop = xf.to_screen(Point::new(175.0, 180.0)); + let later = xf.to_screen(Point::new(300.0, 250.0)); + let alt = egui::Modifiers::ALT; + frame(&mut app, &ctx, 1.5, vec![Event::ModifiersChanged(alt), Event::PointerMoved(drop)]); + let up = Event::PointerButton { pos: drop, button: PointerButton::Primary, pressed: false, modifiers: alt }; + frame(&mut app, &ctx, 1.6, vec![up, Event::PointerMoved(later), Event::ModifiersChanged(egui::Modifiers::NONE)]); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.layers[0].children().map_or(0, Vec::len), 2, "Alt at the release copies the original"); + assert_eq!(st.selection.objects.len(), 1); + let bounds = st.doc.node(st.selection.objects[0]).unwrap().geometric_bounds().unwrap(); + assert!((bounds.x0 - 150.0).abs() < 0.001 && (bounds.y0 - 150.0).abs() < 0.001, "{bounds:?}"); +} + /// Back in the source tab, the move resumes even when coming to the front measured the source's /// type again in its own composite fonts, which replaces the document without editing it. #[test] From 8e59bcb026cb12e8b5134783a9081efefeb6ad35 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 05:21:53 -0800 Subject: [PATCH 5/6] Arrange: the canvas takes a drop where the button went up The canvas took carried artwork only while the pointer was over it at the end of the frame. A release inside the canvas followed in the same frame by a move onto the tab strip kept the drag alive past cleanup, and the drop was lost when the frame ended. The canvas now checks the release position against its own rect and layer, as the tiled and floating panes do (canvas/panes.rs artwork_over). --- crates/ui-egui/src/document_drag.rs | 9 +++++++-- crates/ui-egui/src/tests/document_drag.rs | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/document_drag.rs b/crates/ui-egui/src/document_drag.rs index 53a509e265..836ea0c227 100644 --- a/crates/ui-egui/src/document_drag.rs +++ b/crates/ui-egui/src/document_drag.rs @@ -196,9 +196,14 @@ pub(crate) fn drop_on_canvas(app: &mut VectorcraftApp, resp: &Response, xf: &can if resp.contains_pointer() { resp.ctx.set_cursor_icon(if same && !copy { egui::CursorIcon::Move } else { egui::CursorIcon::Copy }); } - if let Some(art) = resp.dnd_release_payload::() - && let Some(at) = resp.ctx.input(released_at).map(|p| xf.to_doc(p)) + // The canvas takes a release where the button went up, as [`cleanup`] judges it, and not where + // a later move in the same frame leaves the pointer. + let ctx = &resp.ctx; + let over = |p: egui::Pos2| resp.interact_rect.contains(p) && !ctx.layer_id_at(p).is_some_and(|l| l != resp.layer_id); + if let Some(p) = ctx.input(|i| i.pointer.primary_released().then(|| released_at(i)).flatten()).filter(|p| over(*p)) + && let Some(art) = egui::DragAndDrop::take_payload::(ctx) { + let at = xf.to_doc(p); let result = if same { // Back in the source tab, resume the ordinary move (Alt copies). let copy = release_alt(&resp.ctx); diff --git a/crates/ui-egui/src/tests/document_drag.rs b/crates/ui-egui/src/tests/document_drag.rs index dba75e316c..1a3c229386 100644 --- a/crates/ui-egui/src/tests/document_drag.rs +++ b/crates/ui-egui/src/tests/document_drag.rs @@ -316,6 +316,26 @@ fn a_drop_back_in_the_source_uses_the_release_position_and_alt() { assert!((bounds.x0 - 150.0).abs() < 0.001 && (bounds.y0 - 150.0).abs() < 0.001, "{bounds:?}"); } +/// Verify that a release inside the other document's canvas drops the artwork there, though the +/// pointer moves onto the tab strip later in the frame of the release. +#[test] +fn a_release_in_the_canvas_drops_though_the_pointer_then_leaves_it() { + let (mut app, ctx, _, tabs) = drag_fixture(); + frame(&mut app, &ctx, 0.2, vec![Event::PointerMoved(tabs[1].center())]); + frame(&mut app, &ctx, 0.25, vec![]); + frame(&mut app, &ctx, 0.8, vec![]); + assert_eq!(app.session.active_index(), Some(1)); + let before = app.session.active().unwrap().doc.layers[0].children().map_or(0, Vec::len); + let drop = canvas::Xf::new(app.canvas_rect.unwrap(), app.view().unwrap()).to_screen(Point::new(175.0, 180.0)); + assert!(!app.canvas_rect.unwrap().contains(tabs[0].center())); + frame(&mut app, &ctx, 0.9, vec![Event::PointerMoved(drop)]); + frame(&mut app, &ctx, 1.0, vec![button(drop, false), Event::PointerMoved(tabs[0].center())]); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.layers[0].children().map_or(0, Vec::len), before + 1); + let bounds = st.doc.node(st.selection.objects[0]).unwrap().geometric_bounds().unwrap(); + assert!((bounds.x0 - 150.0).abs() < 0.001 && (bounds.y0 - 150.0).abs() < 0.001, "{bounds:?}"); +} + /// Back in the source tab, the move resumes even when coming to the front measured the source's /// type again in its own composite fonts, which replaces the document without editing it. #[test] From a7c7e2bed8aa944ce1af447516801ad1051083cc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 05:33:31 -0800 Subject: [PATCH 6/6] 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. --- crates/ui-egui/src/doc_windows/tests.rs | 32 +++++++++++++++++++++++++ crates/ui-egui/src/document_drag.rs | 8 ++++--- 2 files changed, 37 insertions(+), 3 deletions(-) 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)?;