diff --git a/crates/engine-core/src/cmd/vector_cmds.rs b/crates/engine-core/src/cmd/vector_cmds.rs index 3ffd7a021d..af1b91eae5 100644 --- a/crates/engine-core/src/cmd/vector_cmds.rs +++ b/crates/engine-core/src/cmd/vector_cmds.rs @@ -74,6 +74,7 @@ pub use params::nums; pub use params::op_from; pub use params::pt; pub use params::{parse_path, parse_stroke, path_json}; +pub use paths::PEN_STEP_NAMES; pub use paths::STROKE_PATH_TOOLS; pub use paths::is_work; pub use paths::path_mut; diff --git a/crates/engine-core/src/cmd/vector_cmds/paths.rs b/crates/engine-core/src/cmd/vector_cmds/paths.rs index 7156ddd9ba..f523c68a00 100644 --- a/crates/engine-core/src/cmd/vector_cmds/paths.rs +++ b/crates/engine-core/src/cmd/vector_cmds/paths.rs @@ -80,7 +80,7 @@ const TOOL_HISTORY_NAMES: [&str; 4] = ["Freeform Pen", "Line Tool", "Triangle To /// The names the Pen's per-click path edits record themselves under (#12890): the Work Path is written anchor by /// anchor, and each click is the step the reference application names. They belong to the Pen's drawing, like the /// tool names above; any other `path.set` keeps the normal Work Path or Save Path label. -const PEN_STEP_NAMES: [&str; 6] = ["New Work Path", "New Anchor Point", "Close Path", "New Path Component", "Pick-up Path", "Drag Anchor Point"]; +pub const PEN_STEP_NAMES: [&str; 6] = ["New Work Path", "New Anchor Point", "Close Path", "New Path Component", "Pick-up Path", "Drag Anchor Point"]; /// Validate before editing so malformed automation input cannot change the document. pub(super) fn pen_history_name<'a>(p: &Value, cmd: &str, default: &'a str) -> Result<&'a str> { diff --git a/crates/ui-egui/src/tools/vector_ui/pen.rs b/crates/ui-egui/src/tools/vector_ui/pen.rs index 53777bec40..db8312bddd 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen.rs @@ -516,11 +516,17 @@ pub(super) fn sync_live_draft_from_layer(app: &mut PhotocraftApp) -> Option bool { pub(super) fn start_live_path(app: &mut PhotocraftApp) { let Some(pen) = app.ui.pen.as_ref().filter(|p| starts_live_path(app, p)) else { return }; let append = draft_target(app, pen).is_some(); - // The subpath the write puts in place: the end of the path it joins, else the path's only one. - let index = app.session.active().map_or(0, |st| st.doc.work_path.as_ref().map_or(0, |p| p.subpaths.len())); + // The subpath the write puts in place: joining a path adds it at the end of what is there, so the count the path + // had is its index. A replacing write leaves the drawn path the document's only one (`paths.rs`: `path.set` without + // `op`), however many subpaths the replaced path had, so its subpath is the one at index zero. + let index = if append { app.session.active().map_or(0, |st| st.doc.work_path.as_ref().map_or(0, |p| p.subpaths.len())) } else { 0 }; let mut params = json!({"name": "work", "path": path_json(&pen_path(pen)), "historyName": if append { "New Path Component" } else { "New Work Path" }}); if append { params["op"] = json!("combine"); diff --git a/crates/ui-egui/src/tools/vector_ui/pen_history_steps_tests.rs b/crates/ui-egui/src/tools/vector_ui/pen_history_steps_tests.rs index d40ada59e6..8b907647e7 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen_history_steps_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen_history_steps_tests.rs @@ -214,6 +214,42 @@ fn enter_and_escape_add_no_step_and_name_the_next_click_as_measured() { assert_eq!(subpaths(work(&app).as_ref().unwrap()).len(), 2); } +/// The path that replaces the one Enter finished (#12892 deselects it) is drawn the same live way as a fresh one: the +/// replacing write leaves the drawn path the document's only one, so its subpath is the one at index zero and the +/// clicks after the first are steps of their own. Pinning only the first click let the draft go live nowhere. +#[test] +fn the_path_that_replaces_the_one_enter_finished_is_live_from_its_first_click() { + let mut app = app(); + let before = steps(&app).len(); + triangle(&mut app); + key(&mut app, Key::Enter); + click(&mut app, [60.0, 140.0]); + click(&mut app, [140.0, 60.0]); + assert_eq!(added(&app, before + 3), ["New Work Path", "New Anchor Point"], "every click of the new path is its own step"); + assert_eq!(subpaths(work(&app).as_ref().unwrap()), [(false, vec![[60.0, 140.0], [140.0, 60.0]])], "the first path is replaced, not added to"); + assert_eq!(draft_len(&app), Some(2), "and the Pen is still drawing it"); + assert!(!app.ui.status_error, "{}", app.ui.status); +} + +/// The reviewer's input: three anchors, Undo to two, Redo back to the tip. The state Redo brings back is one of the +/// Pen's own clicks, so the draft follows the path forward too (as it does back) and drawing goes on in that path: +/// otherwise the next click starts a new Work Path over the one that was being drawn. +#[test] +fn redoing_to_the_tip_of_a_live_path_puts_its_click_back_on_the_pen() { + let mut app = app(); + let before = steps(&app).len(); + triangle(&mut app); + menu(&mut app, "edit.undo"); + assert_eq!(draft_len(&app), Some(2), "Undo takes one click back"); + menu(&mut app, "edit.redo"); + testing::move_to(&mut app, [180.0, 180.0], Modifiers::NONE); + assert_eq!(draft_len(&app), Some(3), "Redo to the tip puts that click back on the Pen"); + assert!(!app.ui.status_error, "{}", app.ui.status); + click(&mut app, [180.0, 40.0]); + assert_eq!(added(&app, before + 3), ["New Anchor Point"], "and drawing goes on in the same path"); + assert_eq!(subpaths(work(&app).as_ref().unwrap()), [(false, vec![[20.0, 20.0], [120.0, 20.0], [120.0, 120.0], [180.0, 40.0]])], "not a new path over it"); +} + #[test] fn the_make_shape_button_names_its_step_make_shape_from_path() { let mut app = app();