From beb55416ab05ba30bac89aba1b1596360c59079a Mon Sep 17 00:00:00 2001 From: ljkx <177671075+ljkx@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:28:43 +0100 Subject: [PATCH 1/2] Pen: Delete on a kept draft takes back one anchor, not the whole draft (#15488) A Pen draft whose commit was refused is kept with `commit_failed`, which tells `cancel_stale_pen` to leave it for an explicit retry once its document has changed. `set_draft` cleared that flag on every edit the Pen reported, including the one Delete and Backspace send. After the document changed under the kept draft (Delete under another tool deletes the active layer), the first Delete back under the Pen cleared the flag and the next pass dropped the whole draft as stale. Keep the flag when the draft's owner is stale. Such a draft takes no press (`configure` turns sensing off), so only Delete and Backspace edit it, as before the craft UI port, where only a press cleared the flag. Every other edit still clears it. Adds a_kept_pen_draft_takes_delete_only_under_its_own_tool for the Pen and the Curvature Pen. --- crates/ui-egui/src/tools/vector_ui/host.rs | 5 ++- .../src/tools/vector_ui/pen_resume_tests.rs | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/vector_ui/host.rs b/crates/ui-egui/src/tools/vector_ui/host.rs index c91fa8b7c3..066bae8a85 100644 --- a/crates/ui-egui/src/tools/vector_ui/host.rs +++ b/crates/ui-egui/src/tools/vector_ui/host.rs @@ -308,6 +308,9 @@ fn edit_draft(app: &mut PhotocraftApp, edit: EditEvent) -> bool { fn set_draft(app: &mut PhotocraftApp, value: EditSubpath) { let n = value.knots.len(); let selection_on_draft = app.ui.direct_selection.target == Some(PathRef::Pen); + // A refused draft whose document changed since takes no press, only Delete and Backspace: it stays refused, or + // `cancel_stale_pen` would drop all of it on the next pass instead of the one anchor (#15488). + let stale = app.ui.pen.as_ref().and_then(|p| p.owner.as_ref()).is_some_and(|o| !o.valid(app)); let Some(pen) = ensure_draft(app) else { return }; if pen.draft == value { return; @@ -325,7 +328,7 @@ fn set_draft(app: &mut PhotocraftApp, value: EditSubpath) { } } pen.draft = value; - pen.commit_failed = false; + pen.commit_failed &= stale; if selection_on_draft { let ds = &mut app.ui.direct_selection; if grew { diff --git a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs index 0244f56d10..796b6587c8 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs @@ -735,3 +735,36 @@ fn freeform_selection_does_not_claim_a_failed_pen_or_curvature_draft() { } } } + +/// A refused Pen draft is kept (#15488): under another tool, Delete is that tool's (the active layer goes); back under +/// the Pen that drew it, Delete takes back one anchor at a time, as while drawing, and only the last anchor drops the +/// draft. +#[test] +fn a_kept_pen_draft_takes_delete_only_under_its_own_tool() { + for tool in [Tool::Pen, Tool::CurvaturePen] { + let mut app = app(); + app.run("layer.new.layer", json!({})).unwrap(); + app.ui.tool = tool; + app.ui.tool_options.vector_mode = craft::draw::ui::shape::VectorMode::Path; + three_anchors(&mut app); + app.session.authorize = Some(|id, _| if id == "path.set" { Err(photocraft_engine::EngineError::Other("refused path fixture".into())) } else { Ok(()) }); + assert!(!pen_commit(&mut app, false), "the fixture must actually refuse the commit"); + app.session.authorize = None; + assert_eq!(app.ui.pen.as_ref().unwrap().draft.knots.len(), 3); + let layers = app.session.active().unwrap().doc.layers.len(); + + switch_tool(&mut app, Tool::AddAnchorPoint); + press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); + assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: Delete is the other tool's: the layer goes"); + assert_eq!(app.ui.pen.as_ref().map(|p| p.draft.knots.len()), Some(3), "{tool:?}: the kept draft is untouched"); + + switch_tool(&mut app, tool); + for left in [2, 1] { + press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); + assert_eq!(app.ui.pen.as_ref().map(|p| p.draft.knots.len()), Some(left), "{tool:?}: Delete takes back one anchor ({})", app.ui.status); + } + assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: no other layer went"); + press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); + assert!(app.ui.pen.is_none(), "{tool:?}: the last anchor drops the draft"); + } +} From 3fbff619e4360df204c865317bb0c08f1290af63 Mon Sep 17 00:00:00 2001 From: David Mann Date: Wed, 18 Nov 2026 23:42:00 +0100 Subject: [PATCH 2/2] Pen: the kept-draft Delete test compares the whole draft and checks the layers after the last Delete Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs index c34302ddeb..0da2cd1948 100644 --- a/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs +++ b/crates/ui-egui/src/tools/vector_ui/pen_resume_tests.rs @@ -752,11 +752,12 @@ fn a_kept_pen_draft_takes_delete_only_under_its_own_tool() { app.session.authorize = None; assert_eq!(app.ui.pen.as_ref().unwrap().draft.knots.len(), 3); let layers = app.session.active().unwrap().doc.layers.len(); + let kept = app.ui.pen.as_ref().unwrap().draft.clone(); switch_tool(&mut app, Tool::AddAnchorPoint); press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: Delete is the other tool's: the layer goes"); - assert_eq!(app.ui.pen.as_ref().map(|p| p.draft.knots.len()), Some(3), "{tool:?}: the kept draft is untouched"); + assert_eq!(app.ui.pen.as_ref().map(|p| &p.draft), Some(&kept), "{tool:?}: the kept draft is untouched"); switch_tool(&mut app, tool); for left in [2, 1] { @@ -766,5 +767,6 @@ fn a_kept_pen_draft_takes_delete_only_under_its_own_tool() { assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: no other layer went"); press(&mut app, egui::Key::Delete, egui::Modifiers::NONE); assert!(app.ui.pen.is_none(), "{tool:?}: the last anchor drops the draft"); + assert_eq!(app.session.active().unwrap().doc.layers.len(), layers - 1, "{tool:?}: the last Delete is the drawing tool's too"); } }