test(canvas): pin the Pen anchor row under Option and in Pixels mode

#12915, review nits on the anchor-row change:

- a guard test for the click with Option held: the menu's gate never sees
  the click's modifiers (only open_at receives them), and with Option the
  framework's Pen mode is the Convert overlay, which senses the closed
  square's anchors and straight segments too, so the row appears there as
  well. Observed, now pinned as it is today.
- a guard test for Pixels mode, which the mode check excludes but nothing
  pinned: the Pen's options bar shows Pixels disabled, so the test sets the
  mode option directly.
- the expiry test now reads the accesskit tree like the anchor tools'
  version: the Pen's row is drawn disabled once the path moved, not only
  rejected on click.
- the gate's doc comment says what it does not read (the modifiers) and
  names Pixels mode as an unmeasured case.
This commit is contained in:
hnoerenberg committed 2026-11-19 20:11:21 +01:00
1 parent 98694d2241
commit d46366af48
2 files changed
+41 -7

No files matched your search

@@ -993,8 +993,11 @@ fn point_at(app: &PhotocraftApp, target: PathRef, hit: BezierHit) -> Option<(Str
/// The Pen's menu takes the `target`/`hit` the right-click reported as its point entry only in
/// the measured configuration (#12915): the Pen in Path mode with no path being drawn, and the
/// part on a CLOSED subpath. Its overlay reports the hit exactly as the anchor tools' does (the
/// Auto Add/Delete mode the Pen runs by default). The Shape-mode right-click and an open path's
/// parts are not measured and keep today's plain list, and so does every other case.
/// Auto Add/Delete mode the Pen runs by default). The Shape-mode and Pixels-mode right-click and
/// an open path's parts are not measured and keep today's plain list, and so does every other case.
/// The gate reads no modifiers: `capture` never receives the click's, and with ⌥ held the overlay
/// is Convert, which senses the closed path's anchors and straight segments as well, so the row
/// appears there too - observed and pinned, not measured.
fn pen_point_allowed(app: &PhotocraftApp, target: PathRef, hit: &BezierHit) -> bool {
if app.ui.pen.is_some() || app.ui.tool_options.vector_mode != craft::draw::ui::VectorMode::Path {
return false;
@@ -1,11 +1,12 @@
//! #12915: with the Pen (Path mode) a right-click on a part of the active CLOSED path heads the
//! path menu with one entry above the separator and the usual Pen list: Add Anchor Point on a
//! segment, Delete Anchor Point on an anchor; choosing it runs the engine command, one history
//! step. On empty canvas, on an open subpath, while a path is being drawn, and in Shape mode the
//! menu keeps today's list with no top entry. The shared path document and menu assertions come
//! from `delete_anchor_menu_tests` (#12771).
//! step. On empty canvas, on an open subpath, while a path is being drawn, and in Shape or Pixels
//! mode the menu keeps today's list with no top entry; with ⌥ held the row stays, as the menu does
//! not read the click's modifiers (pinned below). The shared path document and menu assertions
//! come from `delete_anchor_menu_tests` (#12771).
use egui_kittest::kittest::Queryable as _;
use egui_kittest::kittest::{NodeT, Queryable as _};
use serde_json::json;
use super::delete_anchor_menu_tests::{assert_top_entry, saved, setup, steps};
@@ -141,15 +142,45 @@ fn pen_right_click_in_shape_mode_keeps_todays_list() {
assert_no_top_entry(&h, Tool::Pen);
}
/// Pixels mode is not measured either and keeps today's list (the gate names Path, so every other
/// mode is out). The Pen's options bar shows Pixels disabled, so no click can select it and the
/// option is set directly, as the shape tool's Pixels tests do.
#[test]
fn pen_right_click_in_pixels_mode_keeps_todays_list() {
let mut app = setup(Tool::Pen);
app.ui.tool_options.vector_mode = craft::draw::ui::VectorMode::Pixels;
let mut h = harness(app);
let p = screen_of(h.state(), [200.0, 300.0]);
right_click(&mut h, p, Modifiers::NONE);
assert_no_top_entry(&h, Tool::Pen);
}
/// ⌥ is held for the Convert overlay (craft-libs `pen::mode::resolve`), which senses the closed
/// square's anchors and straight segments too, and the framework reports that secondary click's
/// hit whatever the modifiers are: the menu's gate reads the mode and the subpath, not the click's
/// modifiers, so the row appears. Observed, and pinned as it is today; choosing it with ⌥ down is
/// not measured.
#[test]
fn pen_right_click_with_option_held_still_gets_the_anchor_row() {
let mut h = harness(pen_setup());
let p = screen_of(h.state(), [200.0, 300.0]);
right_click(&mut h, p, Modifiers::ALT);
assert_top_entry(&h, Tool::Pen, "Add Anchor Point");
}
/// The entry is about the path as it was when the menu opened: a control-channel edit meanwhile
/// shifts the knots, so choosing the stale entry deletes nothing and adds no step.
/// shifts the knots, so choosing the stale entry deletes nothing and adds no step. It is drawn
/// disabled for the Pen as well, not only rejected on click (#12771 pattern).
#[test]
fn a_pen_point_entry_expires_once_the_path_is_edited() {
let mut h = pen_right_clicked([300.0, 300.0]);
assert_top_entry(&h, Tool::Pen, "Delete Anchor Point");
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();
let after_add = saved(h.state());
assert_eq!(after_add.subpaths[0].knots.len(), 5, "the anchor went in");
h.run();
assert!(h.get_by_label("Delete Anchor Point").accesskit_node().is_disabled(), "disabled once the path is edited");
let n = steps(h.state());
let ctx = h.ctx.clone();
super::choose(h.state_mut(), &ctx, "path.deleteAnchor");