diff --git a/crates/ui-egui/src/menus/parity.rs b/crates/ui-egui/src/menus/parity.rs index 520aca1181..a185b3576e 100644 --- a/crates/ui-egui/src/menus/parity.rs +++ b/crates/ui-egui/src/menus/parity.rs @@ -7,7 +7,7 @@ use crate::menu_catalog::CATALOG; use crate::menus::is_live; /// Minimum number of live catalog items. Raise it when parity grows; never lower it. -pub const FLOOR: usize = 658; +pub const FLOOR: usize = 660; /// One top-level menu's coverage. #[derive(Clone, Debug, serde::Serialize)] diff --git a/crates/ui-egui/src/move_history_names_tests.rs b/crates/ui-egui/src/move_history_names_tests.rs index 2feb8871bc..084c0b65a5 100644 --- a/crates/ui-egui/src/move_history_names_tests.rs +++ b/crates/ui-egui/src/move_history_names_tests.rs @@ -157,3 +157,21 @@ fn an_alt_arrow_nudge_keeps_duplicate_plus_move() { assert_eq!(history(&app), h0 + 1); assert_eq!(newest(&app).as_deref(), Some("Duplicate + Move")); } + +/// A zero offset moves nothing: the step on top (here the paint) keeps its name. +#[test] +fn a_zero_nudge_renames_no_earlier_step() { + let mut app = app(); + for bundle in [false, true] { + app.session.edit_prefs(|p| p.tools.bundle_nudges = bundle); + let before: Vec = app.session.active().unwrap().history.entries().to_vec(); + crate::move_mods::nudge(&mut app, 0.0, 0.0, false); + let after: Vec = app.session.active().unwrap().history.entries().to_vec(); + if after.len() == before.len() { + assert_eq!(after, before, "bundle {bundle}"); + } else { + assert_eq!(after.last().map(String::as_str), Some("Nudge"), "bundle {bundle}"); + assert_eq!(after[..before.len()], before[..], "bundle {bundle}"); + } + } +} diff --git a/crates/ui-egui/src/shape_bounds_box_tests.rs b/crates/ui-egui/src/shape_bounds_box_tests.rs index 813f5bf398..4052ed4dba 100644 --- a/crates/ui-egui/src/shape_bounds_box_tests.rs +++ b/crates/ui-egui/src/shape_bounds_box_tests.rs @@ -298,3 +298,20 @@ fn with_background_jobs_the_scale_step_is_named_and_the_one_before_is_kept() { assert_eq!(after[..before.len()], before[..], "the earlier steps keep their names"); assert_eq!(after.last().map(String::as_str), Some("Transform Path")); } + +/// A switch to another tool during a handle drag ends the drag, also when the new tool shows the +/// box too; the release scales nothing and is still the box's (it doesn't reach the new tool). +#[test] +fn a_tool_switch_during_a_drag_ends_it_and_takes_its_release() { + let (mut app, a, b) = app_with_two_shapes(Tool::Rectangle); + let steps = app.session.active().unwrap().history.past_len(); + let (ba, bb) = (bounds(&app, a), bounds(&app, b)); + tool_event(&mut app, ToolEvent::Down { x: 723.0, y: 451.0, pressure: 1.0 }, NONE); + tool_event(&mut app, ToolEvent::Move { x: 623.0, y: 391.0, pressure: 1.0 }, NONE); + assert!(app.ui.shape_box.is_some()); + app.ui.tool = Tool::PathSelection; + assert!(crate::shape_bounds_box::pointer(&mut app, ToolEvent::Up { x: 623.0, y: 391.0 }, NONE), "the release is the box's"); + assert!(app.ui.shape_box.is_none()); + assert_eq!(app.session.active().unwrap().history.past_len(), steps); + assert_eq!((bounds(&app, a), bounds(&app, b)), (ba, bb)); +} diff --git a/crates/ui-egui/src/tools/move_mods.rs b/crates/ui-egui/src/tools/move_mods.rs index 30fef94d11..9c91eff38c 100644 --- a/crates/ui-egui/src/tools/move_mods.rs +++ b/crates/ui-egui/src/tools/move_mods.rs @@ -273,6 +273,7 @@ pub fn nudge(app: &mut PhotocraftApp, dx: f64, dy: f64, duplicate_first: bool) { return; } let from = if duplicate_first { duplicate(app) } else { None }; + let revision = app.session.active().map(|st| st.revision); let moved = if duplicate_first { // A copy is a state of its own, folded with its move below. app.nudge_bundle.reset(); @@ -282,8 +283,10 @@ pub fn nudge(app: &mut PhotocraftApp, dx: f64, dy: f64, duplicate_first: bool) { }; match moved { // The reference names an arrow-key move "Nudge"; a bundled run is one step with that name. + // Only a move that changed the document: a zero offset records nothing, and the state + // on top is then another edit's. Ok(_) if from.is_none() => { - if let Some(st) = app.session.active_mut() { + if let Some(st) = app.session.active_mut().filter(|st| Some(st.revision) != revision) { st.history.set_current_label(tl!("Nudge")); } } diff --git a/crates/ui-egui/src/tools/shape_bounds_box.rs b/crates/ui-egui/src/tools/shape_bounds_box.rs index d1f96a0f73..4814e11e2d 100644 --- a/crates/ui-egui/src/tools/shape_bounds_box.rs +++ b/crates/ui-egui/src/tools/shape_bounds_box.rs @@ -31,6 +31,8 @@ pub struct Drag { /// document nor an edit under it (Undo, say). doc: photocraft_doc::DocId, revision: u64, + /// The tool it started with: a switch to another tool ends it, even one that shows the box. + tool: Tool, /// The selected shape layers, as at the press. layers: Vec, /// Their union box `[x0, y0, x1, y1]` at the press. @@ -170,7 +172,7 @@ pub fn cancel(app: &mut PhotocraftApp) { pub fn cancel_stale(app: &mut PhotocraftApp) { let Some(d) = app.ui.shape_box.as_ref() else { return }; let current = app.session.active().is_some_and(|st| st.doc.id == d.doc && st.revision == d.revision); - if !current || !shows(app) { + if !current || app.ui.tool != d.tool || !shows(app) { cancel(app); } } @@ -185,7 +187,7 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool let Some(handle) = hit(app, [x, y]) else { return false }; let Some((layers, rect)) = selection(app) else { return false }; let Some((doc, revision)) = app.session.active().map(|st| (st.doc.id, st.revision)) else { return false }; - app.ui.shape_box = Some(Drag { doc, revision, layers, rect, handle, start: [x, y], scale: [1.0, 1.0] }); + app.ui.shape_box = Some(Drag { doc, revision, tool: app.ui.tool, layers, rect, handle, start: [x, y], scale: [1.0, 1.0] }); // The press may have started the Move tool's snapping, which a box drag has none of. app.prefs_rt.snap = None; app.prefs_rt.snap_lines.clear(); @@ -198,9 +200,12 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool true } ToolEvent::Up { x, y } => { + let had = app.ui.shape_box.is_some(); cancel_stale(app); if app.ui.shape_box.is_none() { - return false; + // The release of a drag that was just dropped is still the box's: it must not + // reach the tool that is active now. + return had; } pointer(app, ToolEvent::Move { x, y, pressure: 1.0 }, mods); let Some(d) = app.ui.shape_box.take() else { return true }; diff --git a/crates/ui-egui/src/tools/vector_ui/overlay.rs b/crates/ui-egui/src/tools/vector_ui/overlay.rs index 47784df004..1e50b63b47 100644 --- a/crates/ui-egui/src/tools/vector_ui/overlay.rs +++ b/crates/ui-egui/src/tools/vector_ui/overlay.rs @@ -194,7 +194,10 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform draw_anchor(painter, to_scr([k.anchor.x, k.anchor.y]), true, accent); } } - crate::shape_bounds_box::draw(app, painter, &to_scr, accent); + // Only over the active document, whose selected layers the box frames. + if st.is_some_and(|s| s.doc.id == doc.id) { + crate::shape_bounds_box::draw(app, painter, &to_scr, accent); + } crate::corner_radius::draw(app, painter, &to_scr, accent); } // Pen path in progress, with handles of the last knot and a rubber band to the pointer. While