From 326a8bd78f26583bd605053d2cd4fa2859f189d7 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Wed, 25 Nov 2026 01:33:25 +0100 Subject: [PATCH] fix(vector): the Pen's live Work Path over a replace and a Redo (#12890) The first click of a new path took the subpath index it carries from the path that was in the document before the write. A replacing click sends `path.set` without `op`, and that write leaves the drawn path the document's only one (`vector_cmds/paths.rs`), so after Enter had finished a path with one subpath the draft looked for its anchor at index one, found no subpath there, and never went live: every further click stayed in the draft and made no History step of its own. A click that joins the path selected in the Paths panel still appends with `op`, so the count that path had stays its index there. Redo of one of the Pen's own clicks back to the History tip left no state waiting to be redone, so the live draft did not follow the path: the next pass cancelled it ("Pen draft cancelled because its source document or path changed") and the click after that wrote a new one-anchor Work Path over the path being drawn. `can_redo()` cannot tell that case from a command that replaced the subpath, so the rule now asks who made the state the document is on: the six Pen step names are refused for any other `path.set` (`paths.rs`), so Redo and Step Forward to one of those states rebuild the draft from its path, as stepping back to an earlier state always did, while a command from elsewhere leaves a state under another label and the draft goes stale there (#6593). `PEN_STEP_NAMES` becomes an export of `vector_cmds` so the Pen's route and the allowlist read one list. `the_path_that_replaces_the_one_enter_finished_is_live_from_its_first_click` and `redoing_to_the_tip_of_a_live_path_puts_its_click_back_on_the_pen` fail at 39a3bc5377 - after Enter the steps there are only ["New Work Path"] where the clicks are two, and at the tip of a Redo the draft is gone - and pass here. --- crates/engine-core/src/cmd/vector_cmds.rs | 1 + .../engine-core/src/cmd/vector_cmds/paths.rs | 2 +- crates/ui-egui/src/tools/vector_ui/pen.rs | 22 ++++++++---- .../vector_ui/pen_history_steps_tests.rs | 36 +++++++++++++++++++ 4 files changed, 53 insertions(+), 8 deletions(-) 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();