PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Single Row/Column Marquee: History names the step after the tool (#3031) (#3035)
Valentin Klein3674ed62bdf1
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rsindex d498caea6..27797a61c 100644--- a/crates/engine/src/commands.rs+++ b/crates/engine/src/commands.rs@@ -467,17 +467,26 @@ fn build() -> Vec<CommandSpec> {"Rectangular Selection",[],None,- r##"{"x":i32,"y":i32,"width":u32,"height":u32,"mode":"replace|add|subtract|intersect"="replace","ellipse":bool=false,"antiAlias":bool=true,"feather":px=0}"##,+ r##"{"x":i32,"y":i32,"width":u32,"height":u32,"mode":"replace|add|subtract|intersect"="replace","ellipse":bool=false,"line":"row|column"?,"antiAlias":bool=true,"feather":px=0}"##,has_doc,|s, p| {let get = |k: &str| int_i32("select.rect", p, k).and_then(|v| v.ok_or_else(|| bad("select.rect", format!("missing `{k}`"))));let r = Rect::from_xywh(get("x")?, get("y")?, get("width")?.max(0) as u32, get("height")?.max(0) as u32);let mode = p.get("mode").and_then(Value::as_str).unwrap_or("replace").to_string();let ellipse = p.get("ellipse").and_then(Value::as_bool).unwrap_or(false);+ // The History step is named after the tool: the Single Row / Single Column+ // Marquee send `line` (Photoshop).+ let step = match p.get("line").and_then(Value::as_str) {+ Some("row") => "Single Row Marquee",+ Some("column") => "Single Column Marquee",+ Some(other) => return Err(bad("select.rect", format!("unknown `line` {other:?} (row|column)"))),+ None if ellipse => "Elliptical Marquee",+ None => "Rectangular Marquee",+ };// Options bar: anti-aliased ellipse edges (4x4 supersampled) and Feather (applied to the new shape only).let aa = p.get("antiAlias").and_then(Value::as_bool).unwrap_or(true);let feather = p.get("feather").and_then(Value::as_f64).unwrap_or(0.0).clamp(0.0, 1000.0) as f32;- s.edit(if ellipse { "Elliptical Marquee" } else { "Rectangular Marquee" }, |doc, _| {+ s.edit(step, |doc, _| {let area = doc.bounds();// A marquee dragged past the canvas stops at its edge (Photoshop); the ellipse// keeps the dragged shape and is only cut there.diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rsindex 083490692..e4cbfe57a 100644--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@ -415,6 +415,12 @@ fn marquee_steps_are_named_after_their_tool() {assert_eq!(last(&s).as_deref(), Some("Elliptical Marquee"));s.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 10})).unwrap();assert_eq!(last(&s).as_deref(), Some("Rectangular Marquee"));+ // #3031: the Single Row / Single Column Marquee name theirs; an unknown `line` is an error.+ s.execute("select.rect", json!({"x": 0, "y": 3, "width": 64, "height": 1, "line": "row"})).unwrap();+ assert_eq!(last(&s).as_deref(), Some("Single Row Marquee"));+ s.execute("select.rect", json!({"x": 3, "y": 0, "width": 1, "height": 48, "line": "column"})).unwrap();+ assert_eq!(last(&s).as_deref(), Some("Single Column Marquee"));+ assert!(s.execute("select.rect", json!({"x": 0, "y": 0, "width": 1, "height": 1, "line": "diagonal"})).is_err());}#[test]diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 1f5310388..fbac6ce43 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -4864,8 +4864,12 @@ pub(crate) fn finish_gesture(app: &mut PhotocraftApp, d: Drag) {let Some([x0, y0, x1, y1]) = single_line_drag_px(app, &d) else { return };let mode = selection_mode(app, d.modifiers);let feather = app.ui.tool_options.feather;- let _ =- app.run("select.rect", json!({"x": x0, "y": y0, "width": x1 - x0, "height": y1 - y0, "mode": mode, "antiAlias": false, "feather": feather}));+ // `line` names the History step after the tool (Single Row / Single Column Marquee).+ let line = if d.tool == Tool::SingleRowMarquee { "row" } else { "column" };+ let _ = app.run(+ "select.rect",+ json!({"x": x0, "y": y0, "width": x1 - x0, "height": y1 - y0, "mode": mode, "line": line, "antiAlias": false, "feather": feather}),+ );}Tool::Patch if crate::retouch_ui::patch_drags_selection(app, d.start, d.modifiers) => crate::retouch_ui::finish_patch(app, d.start, [end[0], end[1]]),Tool::ContentAwareMove if crate::retouch_ui::patch_drags_selection(app, d.start, d.modifiers) => {diff --git a/crates/ui-egui/src/marquee_tests.rs b/crates/ui-egui/src/marquee_tests.rsindex 4f00f4469..c5545af73 100644--- a/crates/ui-egui/src/marquee_tests.rs+++ b/crates/ui-egui/src/marquee_tests.rs@@ -744,9 +744,12 @@ fn single_row_and_column_marquee_select_one_pixel_lines() {click_with(&mut app, Tool::SingleRowMarquee, 15.0, 60.2, Modifiers::SHIFT);assert_eq!(bounds(&app), Rect::new(0, 37, 200, 61));assert!(at(&app, 5, 37) > 0.99 && at(&app, 199, 60) > 0.99 && at(&app, 100, 50) < 0.01, "two rows, nothing between");+ let step = |app: &PhotocraftApp| app.session.active().unwrap().history.undo_label().map(str::to_string);+ assert_eq!(step(&app).as_deref(), Some("Single Row Marquee"), "History names the step after the tool (#3031)");click_with(&mut app, Tool::SingleColumnMarquee, 42.9, 80.0, Modifiers::NONE);assert_eq!(bounds(&app), Rect::new(42, 0, 43, 100));+ assert_eq!(step(&app).as_deref(), Some("Single Column Marquee"));click_with(&mut app, Tool::SingleColumnMarquee, 150.5, 3.0, Modifiers::SHIFT);assert_eq!(bounds(&app), Rect::new(42, 0, 151, 100));click_with(&mut app, Tool::SingleColumnMarquee, 42.0, 10.0, Modifiers::ALT);