Skip to content

Pen: Auto Add/Delete on a selected path - #312

Merged
bflatastic merged 2 commits into
storytold:mainfrom
theironchef:fix/pen-auto-add-delete
Oct 7, 2026
Merged

bflatastic merged 2 commits into
storytold:mainfrom
theironchef:fix/pen-auto-add-delete

Conversation

@theironchef

Copy link
Copy Markdown
Contributor

Fixes #311.

Problem: the Pen had no Auto Add/Delete. Over a segment or an anchor of a selected path, it showed the plain Pen cursor and a click started a new path on top of it. The "Disable Auto Add/Delete" preference (Prefs::disable_auto_add_delete) was stored but never read. In Illustrator, the Pen acts as the Add Anchor Point tool over a selected path and as the Delete Anchor Point tool over one of its anchors. Shift while hovering, or that preference, turns this off.

Change

  • crates/tools/src/pen.rs, new auto_add_delete(cx, p, mods, tol), for the selected, editable, non-guide paths:
    • an anchor within the Pen's 5 px tolerance → path.removeAnchor;
    • otherwise a segment within it → path.insertAnchor at that point (both are the commands the Add and Delete Anchor Point tools already run);
    • None when Shift is held or the preference turns it off.
  • The Pen's button-down uses it between paths:
    • after the blend-spine clicks and after "click an end of a selected open path to continue it", so the ends still continue the path;
    • before starting a new path.
  • cursor shows PenAdd / PenDelete for the same cases.
  • While a path is being drawn, clicks go on drawing it, as before.
  • ToolContext::auto_add_delete (tools) carries the preference. The engine fills it with !prefs.disable_auto_add_delete in with_tool_cx.
  • The module doc says how it works.

Tests

  • New pen::tests::clicking_a_selected_path_adds_or_deletes_an_anchor:
    • add on a segment and delete on an anchor, with their cursors;
    • an end still shows the continue cursor;
    • Shift and the preference turned off give the plain cursor and a new path;
    • a click while drawing goes on drawing.
  • It fails without the change (the cursor over a segment is Pen, not PenAdd).
  • New engine test pen_click_on_a_selected_path_adds_an_anchor_unless_disabled, through the session:
    • a click on a selected 3-anchor path's segment gives 4 anchors;
    • after prefs.set {"key": "disableAutoAddDelete", "value": true}, the same click starts a second path and leaves 3.
  • cargo test -p vectorcraft-tools: 189 passed. cargo test -p vectorcraft-engine: 1251 unit tests and the integration tests passed.
  • cargo clippy -p vectorcraft-tools -p vectorcraft-engine --all-targets -- -D warnings (Rust 1.99): clean.
  • cargo fmt --all -- --check: clean.
  • Checked by hand in a release build on Windows with real mouse input, on a selected 3-anchor open path with the Pen:
    • hovering a segment showed the add cursor, and a click added an anchor there (3 → 4, History "Add Anchor Point");
    • hovering an anchor showed the delete cursor, and a click deleted it (4 → 3, "Delete Anchor Point");
    • an end still showed the continue cursor;
    • a Shift-click on a segment started a new path, as did a plain click with disableAutoAddDelete on. With it off again, the click added an anchor.

Fixed build, zoomed: the Pen over a segment of the selected path shows its add mark, over an anchor its delete mark, over an end its continue mark

I didn't run the full cargo xtask ci (wasm step) here. The Pen's hint bar text is unchanged.

Two things are left out. Paths inside a selected group aren't covered: only directly selected paths count, as for continuing a path. Clicking the last anchor of the path being drawn, to retract its handle, isn't handled either.

This touches different lines of pen.rs than #310 (Alt mid-drag) and #241 (Alt-click on an anchor).

🤖 Generated with Claude Code

theironchef and others added 2 commits October 8, 2026 03:22
Between paths, the Pen now adds an anchor where a click lands on a
segment of a selected path and deletes the anchor a click lands on,
with the add and delete cursors while hovering, as in the reference
app. The ends of a selected open path still continue it. Shift held,
or General > Disable Auto Add/Delete (a stored preference nothing read
until now, passed to tools as ToolContext::auto_add_delete), starts a
new path instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sts (review of storytold#312)

The Pen's Auto Add/Delete had its own copy of the anchor and segment hit
tests and of the path.insertAnchor / path.removeAnchor actions the Add
and Delete Anchor Point tools build. draw2 now exposes anchor_in /
segment_in (the hit tests over a given set of paths) and insert_anchor /
remove_anchor, which both tools use. Adds the ROADMAP entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bflatastic
bflatastic force-pushed the fix/pen-auto-add-delete branch from b8aaf5c to 7feeb73 Compare October 7, 2026 20:49
@bflatastic
bflatastic merged commit af8b7c7 into storytold:main Oct 7, 2026
@bflatastic

Copy link
Copy Markdown
Member

Thanks @theironchef, merged! The Pen now adds and deletes anchors on a selected path, Shift turns it off while held, and Preferences › General › Disable Auto Add/Delete is finally read.

I rebased it on main and added one commit on top. The Pen now reuses the Add/Delete Anchor Point tools' hit tests and action builders (draw2::anchor_in / segment_in, insert_anchor / remove_anchor) instead of carrying a second copy, which also drops a per-hover allocation. The ROADMAP is updated too.

Live check: a click on a selected path's segment went from 3 to 4 anchors, and a click on an anchor went back to 3. History shows "Add Anchor Point" / "Delete Anchor Point" with the + / − cursors. A Shift-click, or prefs.set {disableAutoAddDelete: true} over MCP, started a new path instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Pen tool has no Auto Add/Delete on a selected path (the preference does nothing)

2 participants