From 6fb9baedd24105445e74542fe39a549de3a0d490 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Wed, 11 Nov 2026 07:11:03 -0500 Subject: [PATCH 1/6] Delete Anchor Point and Convert Point: right-click opens the path menu with the point's entry on top (#12771, #12744) path_menu now also opens for the Delete Anchor Point and Convert Point tools. When the menu opens, the anchor or segment under the pointer is found with direct_select::hit_active and remembered on the menu: Delete Anchor Point on an anchor, Add Anchor Point on a segment, nothing on empty canvas. That entry heads the menu above a separator and runs path.deleteAnchor or path.addAnchor (one history step). The rest is PEN_MENU unchanged. Opening the menu adds no history step and changes no selection or point. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 76 ++++++++- .../convert_point_menu_tests.rs | 39 +++++ .../delete_anchor_menu_tests.rs | 150 ++++++++++++++++++ .../src/canvas/canvas_tool_menu/tests.rs | 2 +- crates/ui-egui/src/transform_type_tests.rs | 1 + 5 files changed, 264 insertions(+), 4 deletions(-) create mode 100644 crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs create mode 100644 crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 4751e2b1a2..3511f2877b 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -8,7 +8,9 @@ use photocraft_engine::prefs::{self, CanvasColor}; use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; +use crate::direct_select::PathRef; use crate::{PhotocraftApp, state::Tool}; +use photocraft_vector::edit::Hit; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct CanvasToolMenu { @@ -66,6 +68,11 @@ pub struct CanvasToolMenu { /// Opened with the Content-Aware Move tool inside the active selection (#12194). #[serde(default)] pub inside_selection: bool, + /// Opened with the Delete Anchor Point or Convert Point tool over an anchor or a segment of the + /// targeted path (#12771, #12744): the engine command that entry runs and its params. It heads + /// the path menu, above a separator. + #[serde(default)] + pub point: Option<(String, Value)>, } /// A misspelled word in the type layer being edited (`edit.checkSpelling`'s `list` entry). @@ -328,6 +335,7 @@ pub fn open_crop(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, pos: [f32; sampler_at: None, color: None, inside_selection: false, + point: None, }); crate::canvas_popup::mark_open(ctx, menu_id()); true @@ -635,7 +643,46 @@ pub fn magnetic_drawing(app: &PhotocraftApp) -> bool { /// Selection and Direct Selection tools, whose Photoshop menu offers the same whole-path actions /// for the selected path (#1056). pub fn path_menu(tool: Tool) -> bool { - matches!(tool, Tool::Pen | Tool::PathSelection | Tool::DirectSelection) + matches!(tool, Tool::Pen | Tool::PathSelection | Tool::DirectSelection) || point_menu(tool) +} + +/// The anchor tools whose path menu also heads with the entry for the point under the right-click +/// (#12771, #12744). Add Anchor Point (#12710) joins here. +fn point_menu(tool: Tool) -> bool { + matches!(tool, Tool::DeleteAnchorPoint | Tool::ConvertPoint) +} + +/// The anchor or segment of the targeted path under document point `doc`, as the anchor tools hit +/// it (`direct_select::hit_active`): Delete Anchor Point on an anchor, Add Anchor Point on a +/// segment, at the clicked point. `None` on empty canvas, a handle, or the Pen draft, which the +/// engine doesn't edit. +fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value)> { + let (target, _, hit) = crate::direct_select::hit_active(app, doc)?; + let (command, mut params) = match hit { + Hit::Anchor([subpath, knot]) => (POINT_DELETE, json!({"subpath": subpath, "knot": knot})), + Hit::Segment([subpath, knot], t) => (POINT_ADD, json!({"subpath": subpath, "knot": knot, "t": t})), + Hit::Handle(..) => return None, + }; + if target == PathRef::Pen { + return None; + } + if let (Some(o), Some(t)) = (params.as_object_mut(), target.params(app).as_object()) { + o.extend(t.clone()); + } + Some((command.to_string(), params)) +} + +const POINT_DELETE: &str = "path.deleteAnchor"; +const POINT_ADD: &str = "path.addAnchor"; + +/// The label of a menu's top point entry, spelled out so `cargo xtask i18n-coverage` lists it. +fn point_label(command: &str) -> String { + if command == POINT_DELETE { tl!("Delete Anchor Point").to_string() } else { tl!("Add Anchor Point").to_string() } +} + +/// Is `command` the open menu's top point entry? +fn is_point(menu: &CanvasToolMenu, command: &str) -> bool { + menu.point.as_ref().is_some_and(|(c, _)| c == command) } /// Tools whose plain canvas right-click offers the view menu. @@ -680,7 +727,9 @@ pub fn rows(menu: &CanvasToolMenu) -> &'static [Row] { /// Is `command` one of the open menu's rows, and enabled? pub fn available(app: &PhotocraftApp, menu: &CanvasToolMenu, command: &str) -> bool { - (rows(menu).iter().flatten().any(|(_, id)| *id == command) || is_spelling(menu, command) || is_crop(menu, command)) && entry_enabled(app, menu, command) + is_point(menu, command) + || ((rows(menu).iter().flatten().any(|(_, id)| *id == command) || is_spelling(menu, command) || is_crop(menu, command)) + && entry_enabled(app, menu, command)) } /// Is `command` the transform box's current mode (checked in the transform menu)? @@ -820,6 +869,7 @@ pub fn open_transform(app: &mut PhotocraftApp, ctx: &Context, pos: [f32; 2]) -> sampler_at: None, color: None, inside_selection: false, + point: None, }); crate::canvas_popup::mark_open(ctx, menu_id()); true @@ -906,6 +956,7 @@ pub fn open_pasteboard(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, pos: sampler_at: None, color: None, inside_selection: false, + point: None, }); crate::canvas_popup::mark_open(ctx, menu_id()); true @@ -942,6 +993,7 @@ pub fn open_guide(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, mods: egui sampler_at: None, color: None, inside_selection: false, + point: None, }); crate::canvas_popup::mark_open(ctx, menu_id()); true @@ -1083,6 +1135,7 @@ pub fn open_at(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, pos: [f32; 2] && s.doc.selection.as_ref().is_some_and(|sel| sel.sample_channel(d[0].floor() as i32, d[1].floor() as i32, 0) >= 0.5) }) }); + let point = if point_menu(tool) && has_path { doc.filter(|d| d.iter().all(|v| v.is_finite())).and_then(|d| point_at(app, d)) } else { None }; let sampler = if tool == Tool::ColorSampler { doc.and_then(|d| crate::analysis_ui::sampler_at(app, d)) } else { None }; let sampler_at = sampler.and_then(|i| Some((app.session.active_index()?, *app.session.active()?.color_samplers.get(i)?))); // The Eyedropper reads the colour now, under the right-click: all layers, with the Sample @@ -1107,6 +1160,7 @@ pub fn open_at(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, pos: [f32; 2] sampler_at, color, inside_selection, + point, }); crate::canvas_popup::mark_open(ctx, menu_id()); true @@ -1140,6 +1194,7 @@ pub fn open_view(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, pos: [f32; sampler_at: None, color: None, inside_selection: false, + point: None, }); crate::canvas_popup::mark_open(ctx, menu_id()); true @@ -1182,7 +1237,9 @@ pub fn choose(app: &mut PhotocraftApp, ctx: &Context, command: &str) { if !available(app, &menu, command) { return; } - let result = if menu.crop.is_some() { + let result = if is_point(&menu, command) { + menu.point.as_ref().map_or(Ok(()), |(id, params)| app.run(id, params.clone()).map(|_| ())) + } else if menu.crop.is_some() { choose_crop(app, &menu, command) } else if menu.guide { choose_guide(app, ctx, command) @@ -1514,6 +1571,13 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) { selected = Some(command); } } + if let Some((command, _)) = &menu.point { + let item = egui::Button::new(point_label(command)).min_size(egui::vec2(200.0, 20.0)); + if ui.add(item).clicked() { + selected = Some(command.clone()); + } + ui.separator(); + } for row in rows(&menu) { let Some((label, command)) = *row else { ui.separator(); @@ -1568,3 +1632,9 @@ mod pen_free_transform_label_tests; #[cfg(test)] mod make_selection_dialog_tests; + +#[cfg(test)] +mod delete_anchor_menu_tests; + +#[cfg(test)] +mod convert_point_menu_tests; diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs new file mode 100644 index 0000000000..726b2cb442 --- /dev/null +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs @@ -0,0 +1,39 @@ +//! #12744: the Convert Point tool's right-click opens the same path menu as the Delete Anchor +//! Point tool's (#12771), with no Convert Point entry. The shared steps live in +//! `delete_anchor_menu_tests`. + +use egui_kittest::kittest::Queryable; + +use super::delete_anchor_menu_tests::{add_on_the_edge, delete_the_corner, empty_canvas, opening_changes_nothing, right_clicked, saved, setup}; +use crate::state::Tool; + +#[test] +fn right_click_on_an_anchor_offers_delete_anchor_point_on_top_and_it_deletes() { + delete_the_corner(Tool::ConvertPoint); +} + +#[test] +fn right_click_on_a_segment_offers_add_anchor_point_on_top() { + add_on_the_edge(Tool::ConvertPoint); +} + +#[test] +fn right_click_on_empty_canvas_opens_the_path_menu_without_a_top_entry() { + empty_canvas(Tool::ConvertPoint); +} + +#[test] +fn the_menu_has_no_convert_point_entry_and_converts_nothing() { + let before = saved(&setup(Tool::ConvertPoint)); + for at in [[300.0, 300.0], [200.0, 300.0], [500.0, 100.0]] { + let h = right_clicked(Tool::ConvertPoint, at); + assert!(h.state().ui.canvas_tool_menu.is_some(), "the menu opened at {at:?}"); + assert!(h.query_by_label("Convert Point").is_none(), "no Convert Point entry at {at:?}"); + assert_eq!(saved(h.state()), before, "no point converted at {at:?}"); + } +} + +#[test] +fn opening_the_menu_adds_no_history_step_and_converts_no_point() { + opening_changes_nothing(Tool::ConvertPoint); +} diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs new file mode 100644 index 0000000000..319b48d3f9 --- /dev/null +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs @@ -0,0 +1,150 @@ +//! #12771: with the Delete Anchor Point tool a right-click on the canvas opens the Pen's path menu +//! with one entry for what is under the pointer on top: Delete Anchor Point on an anchor, Add +//! Anchor Point on a segment, nothing on empty canvas. Opening it records no history step and +//! leaves the anchor selection alone. The helpers are shared with the Convert Point tests (#12744). + +use egui::Modifiers; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use photocraft_doc::vector::Path; +use serde_json::json; + +use super::tests::{harness, right_click, screen_of}; +use super::{PEN_MENU, rows}; +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +/// 800 x 600 with a saved, targeted **Path 1**: a closed square (100,300)(300,300)(300,500) +/// (100,500), an open line (400,300)->(700,300) and an open S-curve (400,450)->(700,450). +pub(super) fn setup(tool: Tool) -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600})).unwrap(); + let path = json!({"subpaths": [ + {"closed": true, "knots": [[100, 300], [300, 300], [300, 500], [100, 500]]}, + {"closed": false, "knots": [[400, 300], [700, 300]]}, + {"closed": false, "knots": [ + {"anchor": [400, 450], "in": [400, 450], "out": [500, 350]}, + {"anchor": [700, 450], "in": [600, 550], "out": [700, 450]}, + ]}, + ]}); + app.run("path.set", json!({"name": "Path 1", "path": path})).unwrap(); + app.ui.selected_path = Some("Path 1".into()); + app.ui.tool = tool; + app +} + +/// A harness over [`setup`] with the right-click at document point `at` done. +pub(super) fn right_clicked(tool: Tool, at: [f32; 2]) -> Harness<'static, PhotocraftApp> { + let mut h = harness(setup(tool)); + let p = screen_of(h.state(), at); + right_click(&mut h, p, Modifiers::NONE); + h +} + +pub(super) fn saved(app: &PhotocraftApp) -> Path { + app.session.active().unwrap().doc.paths.iter().find(|p| p.name == "Path 1").unwrap().path.clone() +} + +pub(super) fn steps(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().history.entries().len() +} + +/// The path menu is open and its rows are the Pen's, in the Pen's order. +fn assert_path_menu(h: &Harness<'static, PhotocraftApp>, tool: Tool) { + assert!(h.state().ui.canvas_tool_menu.as_ref().is_some_and(|m| m.tool == tool && rows(m) == PEN_MENU), "{tool:?}: the path menu is open"); +} + +/// The first entry of the open menu is `label`, above Create Vector Mask, and is the only one of +/// the two Add / Delete Anchor Point entries shown. +pub(super) fn assert_top_entry(h: &Harness<'static, PhotocraftApp>, tool: Tool, label: &str) { + assert_path_menu(h, tool); + let other = if label == "Delete Anchor Point" { "Add Anchor Point" } else { "Delete Anchor Point" }; + assert!(h.query_by_label(other).is_none(), "{other} is not offered"); + assert!(h.get_by_label(label).rect().top() < h.get_by_label("Create Vector Mask").rect().top(), "{label} heads the menu"); +} + +/// Right-click the corner (300,300), choose Delete Anchor Point: the square stays closed with +/// three anchors and the history gains one step by that name. +pub(super) fn delete_the_corner(tool: Tool) { + let mut h = right_clicked(tool, [300.0, 300.0]); + assert_top_entry(&h, tool, "Delete Anchor Point"); + let before = steps(h.state()); + h.get_by_label("Delete Anchor Point").click(); + h.run_steps(2); + let path = saved(h.state()); + assert!(path.subpaths[0].closed, "the square stays closed"); + assert_eq!(path.subpaths[0].knots.len(), 3); + assert!(path.subpaths[0].knots.iter().all(|k| (k.anchor.x, k.anchor.y) != (300.0, 300.0)), "(300,300) is gone"); + assert_eq!(steps(h.state()), before + 1); + assert_eq!(h.state().session.active().unwrap().history.undo_label(), Some("Delete Anchor Point")); +} + +/// Right-click the top edge (200,300): Add Anchor Point heads the menu and adds one there. +pub(super) fn add_on_the_edge(tool: Tool) { + let mut h = right_clicked(tool, [200.0, 300.0]); + assert_top_entry(&h, tool, "Add Anchor Point"); + let before = steps(h.state()); + h.get_by_label("Add Anchor Point").click(); + h.run_steps(2); + let path = saved(h.state()); + assert_eq!(path.subpaths[0].knots.len(), 5); + let added = &path.subpaths[0].knots[1].anchor; + assert!((added.x - 200.0).abs() < 3.0 && (added.y - 300.0).abs() < 3.0, "the anchor lands where it was clicked: {added:?}"); + assert_eq!(steps(h.state()), before + 1); + assert_eq!(h.state().session.active().unwrap().history.undo_label(), Some("Add Anchor Point")); +} + +/// Right-click empty canvas with the path targeted: the path menu with no top entry. +pub(super) fn empty_canvas(tool: Tool) { + let h = right_clicked(tool, [500.0, 100.0]); + assert_path_menu(&h, tool); + assert!(h.query_by_label("Delete Anchor Point").is_none() && h.query_by_label("Add Anchor Point").is_none(), "no top entry"); + assert!(h.query_by_label("Create Vector Mask").is_some()); +} + +/// Opening the menu on an anchor and on a segment adds no history step, changes no path and +/// leaves the Direct Selection state as it was (here: one anchor selected). +pub(super) fn opening_changes_nothing(tool: Tool) { + for at in [[300.0, 300.0], [200.0, 300.0]] { + let mut app = setup(tool); + // Direct Selection picks the anchor at (100,300); the tool under test takes over. + app.ui.tool = Tool::DirectSelection; + tool_event(&mut app, ToolEvent::Down { x: 100.0, y: 300.0, pressure: 1.0 }, Modifiers::NONE); + tool_event(&mut app, ToolEvent::Up { x: 100.0, y: 300.0 }, Modifiers::NONE); + assert_eq!(app.ui.direct_selection.anchors, vec![[0, 0]], "an anchor is selected"); + app.ui.tool = tool; + let (path, n) = (saved(&app), steps(&app)); + let mut h = harness(app); + // The selection once the first frames have run: Convert Point keeps Direct Selection's, + // Delete Anchor Point already drops it today, menu or not. + let selection = h.state().ui.direct_selection.clone(); + assert_eq!(!selection.anchors.is_empty(), tool == Tool::ConvertPoint, "{tool:?}: selection before the right-click"); + let p = screen_of(h.state(), at); + right_click(&mut h, p, Modifiers::NONE); + assert!(h.state().ui.canvas_tool_menu.is_some(), "the menu opened at {at:?}"); + assert_eq!(steps(h.state()), n, "no history step at {at:?}"); + assert_eq!(h.state().ui.direct_selection, selection, "the anchor selection is as it was at {at:?}"); + assert_eq!(saved(h.state()), path, "no path changed at {at:?}"); + } +} + +#[test] +fn right_click_on_an_anchor_offers_delete_anchor_point_on_top_and_it_deletes() { + delete_the_corner(Tool::DeleteAnchorPoint); +} + +#[test] +fn right_click_on_a_segment_offers_add_anchor_point_on_top() { + add_on_the_edge(Tool::DeleteAnchorPoint); +} + +#[test] +fn right_click_on_empty_canvas_opens_the_path_menu_without_a_top_entry() { + empty_canvas(Tool::DeleteAnchorPoint); +} + +#[test] +fn opening_the_menu_adds_no_history_step_and_keeps_the_anchor_selection() { + opening_changes_nothing(Tool::DeleteAnchorPoint); +} diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs index 008186bfda..8fe14d5254 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/tests.rs @@ -524,7 +524,7 @@ fn zoom_app(w: u32, h: u32) -> PhotocraftApp { app } -fn screen_of(app: &PhotocraftApp, doc: [f32; 2]) -> Pos2 { +pub(super) fn screen_of(app: &PhotocraftApp, doc: [f32; 2]) -> Pos2 { crate::canvas::ViewXform::active(app).unwrap().to_screen(doc[0], doc[1]) } diff --git a/crates/ui-egui/src/transform_type_tests.rs b/crates/ui-egui/src/transform_type_tests.rs index 510db2203f..8699d2aefd 100644 --- a/crates/ui-egui/src/transform_type_tests.rs +++ b/crates/ui-egui/src/transform_type_tests.rs @@ -61,6 +61,7 @@ fn type_layers_offer_free_transform_but_not_distort_or_perspective() { sampler_at: None, color: None, inside_selection: false, + point: None, }; assert!(crate::canvas_tool_menu::available(&app, &menu, "edit.freeTransform")); assert!(!crate::canvas_tool_menu::available(&app, &menu, "edit.transform.distort")); From 4434695f7210c408da5d7fd963e390268c0b0876 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Wed, 11 Nov 2026 07:21:53 -0500 Subject: [PATCH 2/6] Path menu: no point entry on a shape the anchor tools ignore (#12771) The anchor tools ignore a click on a shape with only its own position lock set (#12730, #12825). The menu now reuses that predicate (anchor_tools::ignores, visibility change only) so its Delete or Add Anchor Point entry cannot bypass the rule; the rest of the menu is as before. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 2 +- .../delete_anchor_menu_tests.rs | 17 +++++++++++++++ crates/ui-egui/src/tools/anchor_tools.rs | 21 ++++++++++++------- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 3511f2877b..0b35679f4d 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -663,7 +663,7 @@ fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value)> { Hit::Segment([subpath, knot], t) => (POINT_ADD, json!({"subpath": subpath, "knot": knot, "t": t})), Hit::Handle(..) => return None, }; - if target == PathRef::Pen { + if target == PathRef::Pen || crate::anchor_tools::ignores(app, &target) { return None; } if let (Some(o), Some(t)) = (params.as_object_mut(), target.params(app).as_object()) { diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs index 319b48d3f9..ceacb850cc 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs @@ -148,3 +148,20 @@ fn right_click_on_empty_canvas_opens_the_path_menu_without_a_top_entry() { fn opening_the_menu_adds_no_history_step_and_keeps_the_anchor_selection() { opening_changes_nothing(Tool::DeleteAnchorPoint); } + +/// A shape with only its own position lock is ignored by the anchor tools' click (#12730, #12825), +/// so the menu offers no point entry on its corner either: the rest of the menu is as before. +#[test] +fn a_shape_with_only_its_position_lock_gets_no_point_entry() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600})).unwrap(); + let shape = app.run("shape.create", json!({"kind": "rect", "rect": [450, 100, 200, 150], "fill": "#3070c0"})).unwrap()["layer"].as_u64().unwrap(); + app.run("layer.select", json!({"layer": shape})).unwrap(); + app.run("layer.lockLayers", json!({"position": true})).unwrap(); + app.ui.tool = Tool::DeleteAnchorPoint; + let mut h = harness(app); + let p = screen_of(h.state(), [650.0, 250.0]); + right_click(&mut h, p, Modifiers::NONE); + assert!(h.state().ui.canvas_tool_menu.is_some(), "the menu opens"); + assert!(h.query_by_label("Delete Anchor Point").is_none() && h.query_by_label("Add Anchor Point").is_none(), "no point entry on the locked shape"); +} diff --git a/crates/ui-egui/src/tools/anchor_tools.rs b/crates/ui-egui/src/tools/anchor_tools.rs index bb4c82d3e3..6241156d31 100644 --- a/crates/ui-egui/src/tools/anchor_tools.rs +++ b/crates/ui-egui/src/tools/anchor_tools.rs @@ -38,13 +38,9 @@ pub fn effective(tool: Tool, mods: Modifiers) -> Option { } } -/// What a click at `p` would edit with `tool`: the frontmost path under the pointer and the -/// segment (Add) or anchor (Delete) hit on it. An anchor hit with Add, or a segment with Delete, -/// edits nothing. -fn target(app: &PhotocraftApp, tool: Tool, p: [f64; 2]) -> Option<(PathRef, Path, Hit)> { - let (r, path, hit) = crate::direct_select::hit_active(app, p)?; - // The anchor tools ignore a click on a shape with only its own position lock set (#12730, #12825). - if let PathRef::Layer(id) = r +/// The anchor tools ignore a click on a shape with only its own position lock set (#12730, #12825). +pub(crate) fn ignores(app: &PhotocraftApp, r: &PathRef) -> bool { + if let PathRef::Layer(id) = *r && let Some(st) = app.session.active() && let Some(layer) = st.doc.layer(LayerId(id)) && matches!(layer.content, LayerContent::Shape(_)) @@ -52,6 +48,17 @@ fn target(app: &PhotocraftApp, tool: Tool, p: [f64; 2]) -> Option<(PathRef, Path && let Some(at) = st.doc.path_of(layer.id) && at.split_last().is_some_and(|(_, ancestors)| !st.doc.locks_at(ancestors).any()) { + return true; + } + false +} + +/// What a click at `p` would edit with `tool`: the frontmost path under the pointer and the +/// segment (Add) or anchor (Delete) hit on it. An anchor hit with Add, or a segment with Delete, +/// edits nothing. +fn target(app: &PhotocraftApp, tool: Tool, p: [f64; 2]) -> Option<(PathRef, Path, Hit)> { + let (r, path, hit) = crate::direct_select::hit_active(app, p)?; + if ignores(app, &r) { return None; } match (tool, hit) { From 9f1690f98e59f42fa979d2b2ac80a085e62150ba Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Wed, 11 Nov 2026 08:15:31 -0500 Subject: [PATCH 3/6] Path menu: the point entry resets the shifted anchor selection (#12744) The menu's Delete or Add Anchor Point now takes the same reset as an anchor tool click (anchor_tools::reset_shifted_selection, factored out of apply), carrying the edited path in the menu state. Test: with every anchor selected, Delete from the menu leaves no stale anchor index. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 16 ++++++---- .../convert_point_menu_tests.rs | 29 +++++++++++++++++++ crates/ui-egui/src/tools/anchor_tools.rs | 11 +++++-- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 0b35679f4d..9f97402a73 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -72,7 +72,7 @@ pub struct CanvasToolMenu { /// targeted path (#12771, #12744): the engine command that entry runs and its params. It heads /// the path menu, above a separator. #[serde(default)] - pub point: Option<(String, Value)>, + pub point: Option<(String, Value, PathRef)>, } /// A misspelled word in the type layer being edited (`edit.checkSpelling`'s `list` entry). @@ -656,7 +656,7 @@ fn point_menu(tool: Tool) -> bool { /// it (`direct_select::hit_active`): Delete Anchor Point on an anchor, Add Anchor Point on a /// segment, at the clicked point. `None` on empty canvas, a handle, or the Pen draft, which the /// engine doesn't edit. -fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value)> { +fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value, PathRef)> { let (target, _, hit) = crate::direct_select::hit_active(app, doc)?; let (command, mut params) = match hit { Hit::Anchor([subpath, knot]) => (POINT_DELETE, json!({"subpath": subpath, "knot": knot})), @@ -669,7 +669,7 @@ fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value)> { if let (Some(o), Some(t)) = (params.as_object_mut(), target.params(app).as_object()) { o.extend(t.clone()); } - Some((command.to_string(), params)) + Some((command.to_string(), params, target)) } const POINT_DELETE: &str = "path.deleteAnchor"; @@ -682,7 +682,7 @@ fn point_label(command: &str) -> String { /// Is `command` the open menu's top point entry? fn is_point(menu: &CanvasToolMenu, command: &str) -> bool { - menu.point.as_ref().is_some_and(|(c, _)| c == command) + menu.point.as_ref().is_some_and(|(c, ..)| c == command) } /// Tools whose plain canvas right-click offers the view menu. @@ -1238,7 +1238,11 @@ pub fn choose(app: &mut PhotocraftApp, ctx: &Context, command: &str) { return; } let result = if is_point(&menu, command) { - menu.point.as_ref().map_or(Ok(()), |(id, params)| app.run(id, params.clone()).map(|_| ())) + menu.point.as_ref().map_or(Ok(()), |(id, params, target)| { + app.run(id, params.clone())?; + crate::anchor_tools::reset_shifted_selection(app, *target); + Ok(()) + }) } else if menu.crop.is_some() { choose_crop(app, &menu, command) } else if menu.guide { @@ -1571,7 +1575,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) { selected = Some(command); } } - if let Some((command, _)) = &menu.point { + if let Some((command, ..)) = &menu.point { let item = egui::Button::new(point_label(command)).min_size(egui::vec2(200.0, 20.0)); if ui.add(item).clicked() { selected = Some(command.clone()); diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs index 726b2cb442..5fd407796d 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs @@ -2,9 +2,13 @@ //! Point tool's (#12771), with no Convert Point entry. The shared steps live in //! `delete_anchor_menu_tests`. +use egui::Modifiers; use egui_kittest::kittest::Queryable; use super::delete_anchor_menu_tests::{add_on_the_edge, delete_the_corner, empty_canvas, opening_changes_nothing, right_clicked, saved, setup}; +use super::tests::{harness, right_click, screen_of}; +use crate::canvas::{ToolEvent, tool_event}; +use crate::direct_select::PathRef; use crate::state::Tool; #[test] @@ -37,3 +41,28 @@ fn the_menu_has_no_convert_point_entry_and_converts_nothing() { fn opening_the_menu_adds_no_history_step_and_converts_no_point() { opening_changes_nothing(Tool::ConvertPoint); } + +/// Every anchor selected (a Direct Selection marquee), then Delete Anchor Point from the menu on +/// (300,300): the anchors shift, so no old anchor index stays selected, as after a Delete Anchor +/// Point click. (`app.run` already drops a selection whose revision moved on; the menu then resets +/// one that survives, with the same helper the click uses.) +#[test] +fn deleting_from_the_menu_resets_the_shifted_anchor_selection() { + let mut app = setup(Tool::DirectSelection); + tool_event(&mut app, ToolEvent::Down { x: 50.0, y: 250.0, pressure: 1.0 }, Modifiers::NONE); + tool_event(&mut app, ToolEvent::Move { x: 750.0, y: 550.0, pressure: 1.0 }, Modifiers::NONE); + tool_event(&mut app, ToolEvent::Up { x: 750.0, y: 550.0 }, Modifiers::NONE); + assert!(app.ui.direct_selection.anchors.len() > 3, "every anchor is selected"); + app.ui.tool = Tool::ConvertPoint; + let mut h = harness(app); + assert!(!h.state().ui.direct_selection.anchors.is_empty(), "Convert Point keeps the selection"); + let p = screen_of(h.state(), [300.0, 300.0]); + right_click(&mut h, p, Modifiers::NONE); + // Chosen without a frame after it, which would drop a selection with no owner, as for a click. + let ctx = h.ctx.clone(); + super::choose(h.state_mut(), &ctx, "path.deleteAnchor"); + assert_eq!(saved(h.state()).subpaths[0].knots.len(), 3, "the anchor is gone"); + let ds = &h.state().ui.direct_selection; + assert!(ds.target.is_none_or(|t| t == PathRef::Saved(0)), "the selection is on no other path"); + assert!(ds.anchors.is_empty(), "no stale anchor index: {:?}", ds.anchors); +} diff --git a/crates/ui-egui/src/tools/anchor_tools.rs b/crates/ui-egui/src/tools/anchor_tools.rs index 6241156d31..c19686085f 100644 --- a/crates/ui-egui/src/tools/anchor_tools.rs +++ b/crates/ui-egui/src/tools/anchor_tools.rs @@ -229,9 +229,7 @@ fn apply(app: &mut PhotocraftApp, r: PathRef, hit: Hit, p: [f64; 2]) { _ => app.ui.direct_selection = DirectSelection { target: Some(r), ..Default::default() }, } } - // The anchors shift: a Direct Selection on this path would point at the wrong ones. - Ok(_) if app.ui.direct_selection.target.as_ref() == Some(&r) => app.ui.direct_selection = DirectSelection { target: Some(r), ..Default::default() }, - Ok(_) => {} + Ok(_) => reset_shifted_selection(app, r), Err(e) => { app.ui.status = e; app.ui.status_error = true; @@ -239,6 +237,13 @@ fn apply(app: &mut PhotocraftApp, r: PathRef, hit: Hit, p: [f64; 2]) { } } +/// The anchors of `r` shifted: a Direct Selection on this path would point at the wrong ones. +pub(crate) fn reset_shifted_selection(app: &mut PhotocraftApp, r: PathRef) { + if app.ui.direct_selection.target.as_ref() == Some(&r) { + app.ui.direct_selection = DirectSelection { target: Some(r), ..Default::default() }; + } +} + /// The hover feedback over the Direct Selection overlay: Add highlights the segment under the /// pointer and shows the anchor a click would add; Delete highlights the anchor it would remove. pub fn draw_hover(app: &PhotocraftApp, painter: &egui::Painter, to_scr: &dyn Fn([f64; 2]) -> Pos2, accent: Color32, mods: Modifiers) { From 9f3c268417c280cd7a19c610fc6b0385a38b2da2 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Wed, 11 Nov 2026 08:26:29 -0500 Subject: [PATCH 4/6] Path menu: drop the redundant selection reset (#12744) app.run already drops a Direct Selection whose revision moved on (direct_select::cancel_stale), so after the menu's Delete Anchor Point no shifted anchor index can stay selected, as after a click. The reset helper added in 9f1690f98 did nothing on top of that: anchor_tools.rs and canvas_tool_menu.rs are back to 4434695f7. The test stays, renamed, as a guard. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 16 ++++++---------- .../canvas_tool_menu/convert_point_menu_tests.rs | 5 ++--- crates/ui-egui/src/tools/anchor_tools.rs | 11 +++-------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 9f97402a73..0b35679f4d 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -72,7 +72,7 @@ pub struct CanvasToolMenu { /// targeted path (#12771, #12744): the engine command that entry runs and its params. It heads /// the path menu, above a separator. #[serde(default)] - pub point: Option<(String, Value, PathRef)>, + pub point: Option<(String, Value)>, } /// A misspelled word in the type layer being edited (`edit.checkSpelling`'s `list` entry). @@ -656,7 +656,7 @@ fn point_menu(tool: Tool) -> bool { /// it (`direct_select::hit_active`): Delete Anchor Point on an anchor, Add Anchor Point on a /// segment, at the clicked point. `None` on empty canvas, a handle, or the Pen draft, which the /// engine doesn't edit. -fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value, PathRef)> { +fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value)> { let (target, _, hit) = crate::direct_select::hit_active(app, doc)?; let (command, mut params) = match hit { Hit::Anchor([subpath, knot]) => (POINT_DELETE, json!({"subpath": subpath, "knot": knot})), @@ -669,7 +669,7 @@ fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value, PathRe if let (Some(o), Some(t)) = (params.as_object_mut(), target.params(app).as_object()) { o.extend(t.clone()); } - Some((command.to_string(), params, target)) + Some((command.to_string(), params)) } const POINT_DELETE: &str = "path.deleteAnchor"; @@ -682,7 +682,7 @@ fn point_label(command: &str) -> String { /// Is `command` the open menu's top point entry? fn is_point(menu: &CanvasToolMenu, command: &str) -> bool { - menu.point.as_ref().is_some_and(|(c, ..)| c == command) + menu.point.as_ref().is_some_and(|(c, _)| c == command) } /// Tools whose plain canvas right-click offers the view menu. @@ -1238,11 +1238,7 @@ pub fn choose(app: &mut PhotocraftApp, ctx: &Context, command: &str) { return; } let result = if is_point(&menu, command) { - menu.point.as_ref().map_or(Ok(()), |(id, params, target)| { - app.run(id, params.clone())?; - crate::anchor_tools::reset_shifted_selection(app, *target); - Ok(()) - }) + menu.point.as_ref().map_or(Ok(()), |(id, params)| app.run(id, params.clone()).map(|_| ())) } else if menu.crop.is_some() { choose_crop(app, &menu, command) } else if menu.guide { @@ -1575,7 +1571,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) { selected = Some(command); } } - if let Some((command, ..)) = &menu.point { + if let Some((command, _)) = &menu.point { let item = egui::Button::new(point_label(command)).min_size(egui::vec2(200.0, 20.0)); if ui.add(item).clicked() { selected = Some(command.clone()); diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs index 5fd407796d..d8d8592784 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/convert_point_menu_tests.rs @@ -44,10 +44,9 @@ fn opening_the_menu_adds_no_history_step_and_converts_no_point() { /// Every anchor selected (a Direct Selection marquee), then Delete Anchor Point from the menu on /// (300,300): the anchors shift, so no old anchor index stays selected, as after a Delete Anchor -/// Point click. (`app.run` already drops a selection whose revision moved on; the menu then resets -/// one that survives, with the same helper the click uses.) +/// Point click: `app.run` drops a Direct Selection whose revision moved on (`cancel_stale`). #[test] -fn deleting_from_the_menu_resets_the_shifted_anchor_selection() { +fn deleting_from_the_menu_leaves_no_shifted_anchor_selected() { let mut app = setup(Tool::DirectSelection); tool_event(&mut app, ToolEvent::Down { x: 50.0, y: 250.0, pressure: 1.0 }, Modifiers::NONE); tool_event(&mut app, ToolEvent::Move { x: 750.0, y: 550.0, pressure: 1.0 }, Modifiers::NONE); diff --git a/crates/ui-egui/src/tools/anchor_tools.rs b/crates/ui-egui/src/tools/anchor_tools.rs index c19686085f..6241156d31 100644 --- a/crates/ui-egui/src/tools/anchor_tools.rs +++ b/crates/ui-egui/src/tools/anchor_tools.rs @@ -229,7 +229,9 @@ fn apply(app: &mut PhotocraftApp, r: PathRef, hit: Hit, p: [f64; 2]) { _ => app.ui.direct_selection = DirectSelection { target: Some(r), ..Default::default() }, } } - Ok(_) => reset_shifted_selection(app, r), + // The anchors shift: a Direct Selection on this path would point at the wrong ones. + Ok(_) if app.ui.direct_selection.target.as_ref() == Some(&r) => app.ui.direct_selection = DirectSelection { target: Some(r), ..Default::default() }, + Ok(_) => {} Err(e) => { app.ui.status = e; app.ui.status_error = true; @@ -237,13 +239,6 @@ fn apply(app: &mut PhotocraftApp, r: PathRef, hit: Hit, p: [f64; 2]) { } } -/// The anchors of `r` shifted: a Direct Selection on this path would point at the wrong ones. -pub(crate) fn reset_shifted_selection(app: &mut PhotocraftApp, r: PathRef) { - if app.ui.direct_selection.target.as_ref() == Some(&r) { - app.ui.direct_selection = DirectSelection { target: Some(r), ..Default::default() }; - } -} - /// The hover feedback over the Direct Selection overlay: Add highlights the segment under the /// pointer and shows the anchor a click would add; Delete highlights the anchor it would remove. pub fn draw_hover(app: &PhotocraftApp, painter: &egui::Painter, to_scr: &dyn Fn([f64; 2]) -> Pos2, accent: Color32, mods: Modifiers) { From 384a68d94ce25f396bbcf77131e2110bbd958139 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Wed, 11 Nov 2026 14:51:50 -0500 Subject: [PATCH 5/6] Path menu: a point entry expires once the path changes; undo/redo checked in the menu tests (#12771, #12744) The top point entry now carries the document id and revision it was read from (as the #13150 prompt does); choose and available run nothing once either has moved on, so an edit while the menu is open can no longer delete a shifted anchor. The shared delete and add helpers now undo and redo the menu edit and compare the whole path. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 25 +++++++++++----- .../delete_anchor_menu_tests.rs | 29 +++++++++++++++++++ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 8fd8bc13f6..40c8e96c02 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -74,9 +74,10 @@ pub struct CanvasToolMenu { pub inside_selection: bool, /// Opened with the Delete Anchor Point or Convert Point tool over an anchor or a segment of the /// targeted path (#12771, #12744): the engine command that entry runs and its params. It heads - /// the path menu, above a separator. + /// the path menu, above a separator. The third part is the document id and revision it was read + /// from: the knot index means something only there, so the entry expires once either moves on. #[serde(default)] - pub point: Option<(String, Value)>, + pub point: Option<(String, Value, (u64, u64))>, } /// A misspelled word in the type layer being edited (`edit.checkSpelling`'s `list` entry). @@ -735,7 +736,7 @@ fn point_menu(tool: Tool) -> bool { /// it (`direct_select::hit_active`): Delete Anchor Point on an anchor, Add Anchor Point on a /// segment, at the clicked point. `None` on empty canvas, a handle, or the Pen draft, which the /// engine doesn't edit. -fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value)> { +fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value, (u64, u64))> { let (target, _, hit) = crate::direct_select::hit_active(app, doc)?; let (command, mut params) = match hit { Hit::Anchor([subpath, knot]) => (POINT_DELETE, json!({"subpath": subpath, "knot": knot})), @@ -748,7 +749,8 @@ fn point_at(app: &PhotocraftApp, doc: [f64; 2]) -> Option<(String, Value)> { if let (Some(o), Some(t)) = (params.as_object_mut(), target.params(app).as_object()) { o.extend(t.clone()); } - Some((command.to_string(), params)) + let stamp = app.session.active().map(|st| (st.doc.id.0, st.revision))?; + Some((command.to_string(), params, stamp)) } const POINT_DELETE: &str = "path.deleteAnchor"; @@ -761,7 +763,14 @@ fn point_label(command: &str) -> String { /// Is `command` the open menu's top point entry? fn is_point(menu: &CanvasToolMenu, command: &str) -> bool { - menu.point.as_ref().is_some_and(|(c, _)| c == command) + menu.point.as_ref().is_some_and(|(c, ..)| c == command) +} + +/// Is the open menu's point entry still about the path as it is? The document and its revision are +/// the ones the entry was read from; an edit meanwhile (say a control-channel `path.addAnchor`) +/// shifts the knot indexes, so a stale entry runs nothing. +fn point_current(app: &PhotocraftApp, menu: &CanvasToolMenu) -> bool { + menu.point.as_ref().is_some_and(|(.., stamp)| app.session.active().map(|st| (st.doc.id.0, st.revision)) == Some(*stamp)) } /// Tools whose plain canvas right-click offers the view menu. @@ -808,7 +817,7 @@ pub fn rows(menu: &CanvasToolMenu) -> &'static [Row] { /// Is `command` one of the open menu's rows, and enabled? pub fn available(app: &PhotocraftApp, menu: &CanvasToolMenu, command: &str) -> bool { - is_point(menu, command) + (is_point(menu, command) && point_current(app, menu)) || ((rows(menu).iter().flatten().any(|(_, id)| *id == command) || is_spelling(menu, command) || is_crop(menu, command)) && entry_enabled(app, menu, command)) } @@ -1367,7 +1376,7 @@ pub fn choose(app: &mut PhotocraftApp, ctx: &Context, command: &str) { return; } let result = if is_point(&menu, command) { - menu.point.as_ref().map_or(Ok(()), |(id, params)| app.run(id, params.clone()).map(|_| ())) + menu.point.as_ref().map_or(Ok(()), |(id, params, _)| app.run(id, params.clone()).map(|_| ())) } else if menu.crop.is_some() { choose_crop(app, &menu, command) } else if menu.guide { @@ -1716,7 +1725,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) { selected = Some(command); } } - if let Some((command, _)) = &menu.point { + if let Some((command, ..)) = &menu.point { let item = egui::Button::new(point_label(command)).min_size(egui::vec2(200.0, 20.0)); if ui.add(item).clicked() { selected = Some(command.clone()); diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs index ceacb850cc..0d6f1923c4 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs @@ -64,12 +64,22 @@ pub(super) fn assert_top_entry(h: &Harness<'static, PhotocraftApp>, tool: Tool, assert!(h.get_by_label(label).rect().top() < h.get_by_label("Create Vector Mask").rect().top(), "{label} heads the menu"); } +/// The context-menu contract after a menu edit: undo restores the whole original path and redo +/// replays the edit (the path as it was right after the menu choice, `edited`). +fn assert_undo_redo(h: &mut Harness<'static, PhotocraftApp>, original: &Path, edited: &Path) { + h.state_mut().run("edit.undo", json!({})).unwrap(); + assert_eq!(&saved(h.state()), original, "undo restores the whole path"); + h.state_mut().run("edit.redo", json!({})).unwrap(); + assert_eq!(&saved(h.state()), edited, "redo replays the menu edit"); +} + /// Right-click the corner (300,300), choose Delete Anchor Point: the square stays closed with /// three anchors and the history gains one step by that name. pub(super) fn delete_the_corner(tool: Tool) { let mut h = right_clicked(tool, [300.0, 300.0]); assert_top_entry(&h, tool, "Delete Anchor Point"); let before = steps(h.state()); + let original = saved(h.state()); h.get_by_label("Delete Anchor Point").click(); h.run_steps(2); let path = saved(h.state()); @@ -78,6 +88,7 @@ pub(super) fn delete_the_corner(tool: Tool) { assert!(path.subpaths[0].knots.iter().all(|k| (k.anchor.x, k.anchor.y) != (300.0, 300.0)), "(300,300) is gone"); assert_eq!(steps(h.state()), before + 1); assert_eq!(h.state().session.active().unwrap().history.undo_label(), Some("Delete Anchor Point")); + assert_undo_redo(&mut h, &original, &path); } /// Right-click the top edge (200,300): Add Anchor Point heads the menu and adds one there. @@ -85,6 +96,7 @@ pub(super) fn add_on_the_edge(tool: Tool) { let mut h = right_clicked(tool, [200.0, 300.0]); assert_top_entry(&h, tool, "Add Anchor Point"); let before = steps(h.state()); + let original = saved(h.state()); h.get_by_label("Add Anchor Point").click(); h.run_steps(2); let path = saved(h.state()); @@ -93,6 +105,7 @@ pub(super) fn add_on_the_edge(tool: Tool) { assert!((added.x - 200.0).abs() < 3.0 && (added.y - 300.0).abs() < 3.0, "the anchor lands where it was clicked: {added:?}"); assert_eq!(steps(h.state()), before + 1); assert_eq!(h.state().session.active().unwrap().history.undo_label(), Some("Add Anchor Point")); + assert_undo_redo(&mut h, &original, &path); } /// Right-click empty canvas with the path targeted: the path menu with no top entry. @@ -149,6 +162,22 @@ fn opening_the_menu_adds_no_history_step_and_keeps_the_anchor_selection() { opening_changes_nothing(Tool::DeleteAnchorPoint); } +/// The entry is about the path as it was when the menu opened: an edit meanwhile (a control call +/// inserting an anchor before the corner) shifts the knots, so choosing it deletes nothing. +#[test] +fn a_point_entry_expires_once_the_path_is_edited() { + let mut h = right_clicked(Tool::DeleteAnchorPoint, [300.0, 300.0]); + assert_top_entry(&h, Tool::DeleteAnchorPoint, "Delete Anchor Point"); + h.state_mut().run("path.addAnchor", json!({"name": "Path 1", "subpath": 0, "knot": 0, "t": 0.5})).unwrap(); + let after_add = saved(h.state()); + assert_eq!(after_add.subpaths[0].knots.len(), 5, "the anchor went in"); + let n = steps(h.state()); + let ctx = h.ctx.clone(); + super::choose(h.state_mut(), &ctx, "path.deleteAnchor"); + assert_eq!(saved(h.state()), after_add, "the stale entry deleted nothing"); + assert_eq!(steps(h.state()), n, "and added no history step"); +} + /// A shape with only its own position lock is ignored by the anchor tools' click (#12730, #12825), /// so the menu offers no point entry on its corner either: the rest of the menu is as before. #[test] From 51f001c929cdcb7a3604715a500f2702ce811697 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Wed, 11 Nov 2026 16:02:55 -0500 Subject: [PATCH 6/6] Path menu: an expired point entry is drawn disabled (#12771) Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/canvas/canvas_tool_menu.rs | 2 +- .../canvas_tool_menu/delete_anchor_menu_tests.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 40c8e96c02..c66d036d94 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -1727,7 +1727,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &Context) { } if let Some((command, ..)) = &menu.point { let item = egui::Button::new(point_label(command)).min_size(egui::vec2(200.0, 20.0)); - if ui.add(item).clicked() { + if ui.add_enabled(available(app, &menu, command), item).clicked() { selected = Some(command.clone()); } ui.separator(); diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs index 0d6f1923c4..7db812349d 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu/delete_anchor_menu_tests.rs @@ -5,7 +5,7 @@ use egui::Modifiers; use egui_kittest::Harness; -use egui_kittest::kittest::Queryable; +use egui_kittest::kittest::{NodeT, Queryable}; use photocraft_doc::vector::Path; use serde_json::json; @@ -178,6 +178,16 @@ fn a_point_entry_expires_once_the_path_is_edited() { assert_eq!(steps(h.state()), n, "and added no history step"); } +/// The expired entry is drawn disabled, not just rejected on click (#12771, CodeRabbit). +#[test] +fn an_expired_point_entry_is_drawn_disabled() { + let mut h = right_clicked(Tool::DeleteAnchorPoint, [300.0, 300.0]); + assert!(!h.get_by_label("Delete Anchor Point").accesskit_node().is_disabled(), "enabled while the path is as it was"); + h.state_mut().run("path.addAnchor", json!({"name": "Path 1", "subpath": 0, "knot": 0, "t": 0.5})).unwrap(); + h.run(); + assert!(h.get_by_label("Delete Anchor Point").accesskit_node().is_disabled(), "disabled once the path is edited"); +} + /// A shape with only its own position lock is ignored by the anchor tools' click (#12730, #12825), /// so the menu offers no point entry on its corner either: the rest of the menu is as before. #[test]