mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
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.
This commit is contained in:
1 parent
39a3bc5377
commit
326a8bd78f
4 files changed
+53
-8
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -516,11 +516,17 @@ pub(super) fn sync_live_draft_from_layer(app: &mut PhotocraftApp) -> Option<Edit
|
||||
if pen.live_layer {
|
||||
return rebuild_live_draft(app);
|
||||
}
|
||||
// A live Work Path draft follows its path when the document stepped back to an earlier state (Undo, Redo, the
|
||||
// History panel: a state is waiting to be redone). A command that replaced its subpath left a new state behind
|
||||
// instead: like any other draft that carried a path on (#6593) it is stale, and `cancel_stale_pen` drops it with
|
||||
// the reason rather than quietly going on with the newer path's anchors.
|
||||
if app.session.active().is_some_and(|st| st.history.can_redo()) { rebuild_live_draft(app) } else { None }
|
||||
// A live Work Path draft follows its path when the document moved to a state the Pen's own clicks made: back to an
|
||||
// earlier one (Undo, Step Backward, the History panel: a state is waiting to be redone) or forward to one of its
|
||||
// clicks (Redo, Step Forward, the History panel at the tip). The six step names belong to those writes alone -
|
||||
// `paths.rs` refuses them for any other `path.set` - so the step the document is on names who made it. A command
|
||||
// from elsewhere left a newer state instead: like any other draft that carried a path on (#6593) it is stale, and
|
||||
// `cancel_stale_pen` drops it with the reason rather than quietly going on with the newer path's anchors.
|
||||
let pen_stepped_its_own_path = app
|
||||
.session
|
||||
.active()
|
||||
.is_some_and(|st| st.history.can_redo() || photocraft_engine::vector_cmds::PEN_STEP_NAMES.iter().any(|n| st.history.undo_label() == Some(*n)));
|
||||
if pen_stepped_its_own_path { rebuild_live_draft(app) } else { None }
|
||||
}
|
||||
|
||||
/// Rebuilds a live draft from its layer's or path's open subpath and hands it to the Pen, or drops it when the subpath
|
||||
@@ -584,8 +590,10 @@ fn starts_live_path(app: &PhotocraftApp, pen: &PenPath) -> 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");
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user