Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Pen: Auto Add/Delete anchors on the active path (#4144) (#4540)

bazc1e3ae9f162b
diff --git a/crates/ui-egui/src/anchor_tools.rs b/crates/ui-egui/src/anchor_tools.rs
index a314db5fc..149792b39 100644
--- a/crates/ui-egui/src/anchor_tools.rs
+++ b/crates/ui-egui/src/anchor_tools.rs
@@ -7,6 +7,9 @@
//! * Delete Anchor Point: hovering an anchor highlights it; a click removes it
//! (`path.deleteAnchor`), joining its neighbours.
//! * ⌥ swaps the two tools and ⌘/Ctrl is Direct Selection (`direct_select`) while held.
+//! * The Pen does both with Auto Add/Delete on (its options bar, on by default, #4144), on the
+//! active path only and while no path is being drawn: a click on a segment adds, a click on an
+//! anchor deletes, except an open subpath's end points; ⇧ turns it off while held.
//!
//! Each click is one command and one history step; a click on nothing it can edit does nothing.
@@ -43,8 +46,42 @@ fn target(app: &PhotocraftApp, tool: Tool, p: [f64; 2]) -> Option<(PathRef, Path
}
}
-/// Canvas pointer events for the anchor tools; false when the current tool isn't one.
+/// The Pen's Auto Add/Delete (#4144): what a Pen click at `p` does to the active path instead of
+/// starting a new one, as the anchor tool that does it (Add Anchor Point on a segment, Delete
+/// Anchor Point on an anchor), the path and the hit. `None` when the option is off, ⇧, ⌥ or ⌘ is
+/// held, a path is being drawn, or the click hits nothing it edits. The end points of an open
+/// subpath are left to the Pen, as in Photoshop.
+pub fn pen_auto(app: &PhotocraftApp, tool: Tool, mods: Modifiers, p: [f64; 2]) -> Option<(Tool, PathRef, Path, Hit)> {
+ if tool != Tool::Pen || !app.ui.tool_options.pen_auto_add_delete || app.ui.pen.is_some() || mods.shift || mods.alt || mods.command {
+ return None;
+ }
+ let tol = 6.0 / f64::from(app.point_zoom().max(0.01));
+ let (r, path, hit) =
+ crate::direct_select::active_paths(app).into_iter().find_map(|(r, path)| edit::hit(&path, Point::new(p[0], p[1]), tol, &[]).map(|h| (r, path, h)))?;
+ let tool = match hit {
+ Hit::Segment(..) => Tool::AddAnchorPoint,
+ Hit::Anchor([s, k]) => {
+ let sp = path.subpaths.get(s)?;
+ if !sp.closed && (k == 0 || k + 1 == sp.knots.len()) {
+ return None;
+ }
+ Tool::DeleteAnchorPoint
+ }
+ Hit::Handle(..) => return None,
+ };
+ Some((tool, r, path, hit))
+}
+
+/// Canvas pointer events for the anchor tools, and a Pen press that Auto Add/Delete takes; false
+/// when they aren't theirs.
pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool {
+ if let ToolEvent::Down { x, y, .. } = ev
+ && let Some((_, r, _, hit)) = pen_auto(app, app.ui.tool, mods, [x, y])
+ {
+ // The release finds no Pen path to finish, so the Pen draws nothing.
+ apply(app, r, hit);
+ return true;
+ }
let Some(tool) = effective(app.ui.tool, mods) else { return false };
if let ToolEvent::Down { x, y, .. } = ev {
click(app, tool, [x, y]);
@@ -54,6 +91,11 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool
fn click(app: &mut PhotocraftApp, tool: Tool, p: [f64; 2]) {
let Some((r, _, hit)) = target(app, tool, p) else { return };
+ apply(app, r, hit);
+}
+
+/// Add an anchor where `hit` is on a segment of `r`, or delete the anchor it is on: one command.
+fn apply(app: &mut PhotocraftApp, r: PathRef, hit: Hit) {
let (id, mut params) = match hit {
Hit::Segment([s, k], t) => ("path.addAnchor", serde_json::json!({"subpath": s, "knot": k, "t": t})),
Hit::Anchor([s, k]) => ("path.deleteAnchor", serde_json::json!({"subpath": s, "knot": k})),
@@ -82,6 +124,18 @@ pub fn draw_hover(app: &PhotocraftApp, painter: &egui::Painter, to_scr: &dyn Fn(
return;
}
let Some((_, path, hit)) = target(app, tool, p) else { return };
+ draw_hit(painter, to_scr, accent, &path, hit);
+}
+
+/// The same feedback for the Pen when Auto Add/Delete would act on a click.
+pub fn draw_pen_hover(app: &PhotocraftApp, painter: &egui::Painter, to_scr: &dyn Fn([f64; 2]) -> Pos2, accent: Color32, mods: Modifiers) {
+ let Some(p) = app.hover_doc else { return };
+ if let Some((_, _, path, hit)) = pen_auto(app, app.ui.tool, mods, p) {
+ draw_hit(painter, to_scr, accent, &path, hit);
+ }
+}
+
+fn draw_hit(painter: &egui::Painter, to_scr: &dyn Fn([f64; 2]) -> Pos2, accent: Color32, path: &Path, hit: Hit) {
match hit {
Hit::Segment([s, k], t) => {
let Some(seg) = path.subpaths.get(s).and_then(|sp| sp.segments().get(k).copied()) else { return };
diff --git a/crates/ui-egui/src/anchor_tools_tests.rs b/crates/ui-egui/src/anchor_tools_tests.rs
index c88f1a2b1..87c045eba 100644
--- a/crates/ui-egui/src/anchor_tools_tests.rs
+++ b/crates/ui-egui/src/anchor_tools_tests.rs
@@ -154,3 +154,79 @@ fn the_cursor_shows_plus_or_minus() {
assert_eq!(badge(&app, Tool::DeleteAnchorPoint, Modifiers::NONE), Some(Badge::Subtract));
assert_eq!(badge(&app, Tool::DeleteAnchorPoint, Modifiers::COMMAND), None, "⌘ is Direct Selection");
}
+
+/// #4144: with Auto Add/Delete (on by default) a Pen click on a segment of the active path adds
+/// an anchor and a click on one of its anchors deletes it, one step each, and no Pen path starts.
+#[test]
+fn the_pen_adds_and_deletes_anchors_on_the_active_path() {
+ let mut app = app(Tool::Pen);
+ assert!(app.ui.tool_options.pen_auto_add_delete, "on by default, as in Photoshop");
+ with_path(&mut app);
+ let n = steps(&app);
+ click(&mut app, [80.0, 120.0], Modifiers::NONE);
+ assert_eq!(work(&app).subpaths[0].knots.len(), 5);
+ assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Add Anchor Point"));
+ assert!(app.ui.pen.is_none(), "no Pen path was started");
+ click(&mut app, [40.0, 120.0], Modifiers::NONE);
+ let p = work(&app);
+ assert_eq!(p.subpaths[0].knots.len(), 4);
+ assert!(!p.subpaths[0].knots.iter().any(|k| k.anchor == Point::new(40.0, 120.0)));
+ assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Delete Anchor Point"));
+ assert_eq!(steps(&app), n + 2);
+ assert!(app.ui.pen.is_none());
+ // Off the path the Pen draws.
+ click(&mut app, [170.0, 170.0], Modifiers::NONE);
+ assert_eq!(app.ui.pen.as_ref().map(|p| p.knots.len()), Some(1));
+}
+
+/// Auto Add/Delete off, or ⇧ held, or a path being drawn: the Pen click places an anchor.
+#[test]
+fn the_pen_draws_over_the_path_with_auto_add_delete_off_shift_or_while_drawing() {
+ let mut app = app(Tool::Pen);
+ with_path(&mut app);
+ let before = work(&app);
+ app.ui.tool_options.pen_auto_add_delete = false;
+ click(&mut app, [80.0, 120.0], Modifiers::NONE);
+ assert_eq!((work(&app), app.ui.pen.as_ref().map(|p| p.knots.len())), (before.clone(), Some(1)));
+ app.ui.pen = None;
+
+ app.ui.tool_options.pen_auto_add_delete = true;
+ click(&mut app, [80.0, 120.0], Modifiers::SHIFT);
+ assert_eq!((work(&app), app.ui.pen.as_ref().map(|p| p.knots.len())), (before.clone(), Some(1)), "⇧ turns it off");
+ app.ui.pen = None;
+
+ click(&mut app, [170.0, 170.0], Modifiers::NONE);
+ click(&mut app, [80.0, 120.0], Modifiers::NONE);
+ assert_eq!((work(&app), app.ui.pen.as_ref().map(|p| p.knots.len())), (before, Some(2)), "a path being drawn takes the click");
+}
+
+/// The end points of an open subpath stay the Pen's; its middle anchors are deleted.
+#[test]
+fn the_pen_leaves_open_end_points_alone() {
+ let mut app = app(Tool::Pen);
+ let path = json!({"subpaths": [{"closed": false, "knots": [[40, 40], [120, 40], [120, 120]]}]});
+ app.run("path.set", json!({"name": "work", "path": path})).unwrap();
+ let before = work(&app);
+ for end in [[40.0, 40.0], [120.0, 120.0]] {
+ click(&mut app, end, Modifiers::NONE);
+ assert_eq!(work(&app), before, "{end:?}");
+ app.ui.pen = None;
+ }
+ click(&mut app, [120.0, 40.0], Modifiers::NONE);
+ assert_eq!(work(&app).subpaths[0].knots.len(), 2);
+}
+
+#[test]
+fn the_pen_cursor_shows_what_auto_add_delete_would_do() {
+ use crate::tool_feedback::{Badge, badge};
+ let mut app = app(Tool::Pen);
+ with_path(&mut app);
+ for (at, want) in [([80.0, 120.0], Some(Badge::Add)), ([40.0, 120.0], Some(Badge::Subtract)), ([80.0, 80.0], None)] {
+ app.hover_doc = Some(at);
+ assert_eq!(badge(&app, Tool::Pen, Modifiers::NONE), want, "{at:?}");
+ }
+ app.hover_doc = Some([80.0, 120.0]);
+ assert_eq!(badge(&app, Tool::Pen, Modifiers::SHIFT), None);
+ app.ui.tool_options.pen_auto_add_delete = false;
+ assert_eq!(badge(&app, Tool::Pen, Modifiers::NONE), None);
+}
diff --git a/crates/ui-egui/src/direct_select.rs b/crates/ui-egui/src/direct_select.rs
index 01deb0a07..b18361828 100644
--- a/crates/ui-egui/src/direct_select.rs
+++ b/crates/ui-egui/src/direct_select.rs
@@ -134,12 +134,17 @@ pub fn shows(app: &PhotocraftApp, mods: Modifiers) -> bool {
|| matches!(app.ui.tool, Tool::AddAnchorPoint | Tool::DeleteAnchorPoint | Tool::ConvertPoint)
}
-/// The paths Direct Selection edits, front first: the targeted vector mask or the active shape
-/// layer's path, then the work path.
-pub(crate) fn candidates(app: &PhotocraftApp) -> Vec<(PathRef, Path)> {
+/// The active paths, front first: the targeted vector mask or the active shape layer's path, then
+/// the work path. The Pen's Auto Add/Delete edits these (`anchor_tools::pen_auto`).
+pub(crate) fn active_paths(app: &PhotocraftApp) -> Vec<(PathRef, Path)> {
let layer = crate::vector_ui::targeted_vector_mask(app).or_else(|| crate::vector_ui::active_shape_path(app));
let work = app.session.active().and_then(|st| st.doc.work_path.clone());
- let mut out: Vec<_> = layer.map(|(id, p)| (PathRef::Layer(id), p)).into_iter().chain(work.map(|p| (PathRef::Work, p))).collect();
+ layer.map(|(id, p)| (PathRef::Layer(id), p)).into_iter().chain(work.map(|p| (PathRef::Work, p))).collect()
+}
+
+/// The paths Direct Selection edits, front first: the active paths, then every visible shape layer.
+pub(crate) fn candidates(app: &PhotocraftApp) -> Vec<(PathRef, Path)> {
+ let mut out = active_paths(app);
if let Some(st) = app.session.active() {
for (path, _, l) in st.doc.walk().iter().rev() {
if !l.visible || !(1..=path.len()).all(|n| st.doc.layer_at(&path[..n]).is_some_and(|a| a.visible)) {
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 2a9c4a9d5..e6ebb2963 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -3698,3 +3698,4 @@ navigator Zoom Zvětšení
Action playback stopped Přehrávání akce zastaveno
Step {step} is waiting for its dialog Krok {step} čeká na svůj dialog
@plural {n} action|{n} actions {n} akce|{n} akce|{n} akcí
+ Auto Add/Delete Automaticky přidat/odstranit
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index d209af709..a8efbdd68 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -2730,3 +2730,4 @@ curves Smooth Glätten
Action playback stopped Aktionswiedergabe angehalten
Step {step} is waiting for its dialog Schritt {step} wartet auf seinen Dialog
@plural {n} action|{n} actions {n} Aktion|{n} Aktionen
+ Auto Add/Delete Autom. hinzuf./löschen
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index e27766fef..ac29108ad 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -3788,3 +3788,4 @@ curves Smooth Εξομάλυνση
Action playback stopped Η αναπαραγωγή της ενέργειας σταμάτησε
Step {step} is waiting for its dialog Το βήμα {step} περιμένει το παράθυρο διαλόγου του
@plural {n} action|{n} actions {n} ενέργεια|{n} ενέργειες
+ Auto Add/Delete Αυτόματη προσθήκη/διαγραφή
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 62886211e..0a87b5243 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -2771,3 +2771,4 @@ curves Smooth Suavizar
Action playback stopped Reproducción de la acción detenida
Step {step} is waiting for its dialog El paso {step} está esperando su cuadro de diálogo
@plural {n} action|{n} actions {n} acción|{n} acciones
+ Auto Add/Delete Añadir/eliminar automáticamente
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index 7789b2c02..a8e9e2bf3 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -3091,3 +3091,4 @@ curves Smooth Lisser
Action playback stopped Exécution de l’action arrêtée
Step {step} is waiting for its dialog L’étape {step} attend sa boîte de dialogue
@plural {n} action|{n} actions {n} action|{n} actions
+ Auto Add/Delete Ajout/suppr. auto
diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv
index 1c9f15f0b..0775780a4 100644
--- a/crates/ui-egui/src/i18n/hu.tsv
+++ b/crates/ui-egui/src/i18n/hu.tsv
@@ -4010,3 +4010,4 @@ cameraRaw Yellow Sárga
Load settings from a Camera Raw .xmp file Beállítások betöltése Camera Raw .xmp-fájlból
Loaded Camera Raw settings from {file} Camera Raw-beállítások betöltve innen: {file}
Loaded Camera Raw settings from {file} ({n} not supported) Camera Raw-beállítások betöltve innen: {file} ({n} nem támogatott)
+ Auto Add/Delete Automatikus hozzáadás/törlés
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index cb77490c4..f4c53e49b 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -3078,3 +3078,4 @@ curves Smooth Haluskan
Action playback stopped Pemutaran tindakan dihentikan
Step {step} is waiting for its dialog Langkah {step} menunggu dialognya
@plural {n} action|{n} actions {n} tindakan
+ Auto Add/Delete Tambah/Hapus Otomatis
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 288353a61..5b12254b1 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -4054,3 +4054,4 @@ navigator Zoom Zoom
Action playback stopped Esecuzione dell’azione interrotta
Step {step} is waiting for its dialog Il passaggio {step} attende la sua finestra di dialogo
@plural {n} action|{n} actions {n} azione|{n} azioni
+ Auto Add/Delete Aggiungi/elimina automaticamente
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index 26a31ce4d..c6a1ac777 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -3700,3 +3700,4 @@ curves Smooth スムーズ
Action playback stopped アクションの再生を停止しました
Step {step} is waiting for its dialog ステップ {step} はダイアログを待っています
@plural {n} action|{n} actions アクション {n} 個
+ Auto Add/Delete 自動追加・削除
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index b6a95907d..166a2c794 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -3260,3 +3260,4 @@ curves Smooth 매끄럽게
Action playback stopped 액션 재생이 중지되었습니다
Step {step} is waiting for its dialog {step}단계가 대화 상자를 기다리고 있습니다
@plural {n} action|{n} actions 액션 {n}개
+ Auto Add/Delete 자동 추가/삭제
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index 1ec6d64b0..10ebe0fd5 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -3850,3 +3850,4 @@ curves Smooth Vloeiend maken
Action playback stopped Afspelen van de handeling gestopt
Step {step} is waiting for its dialog Stap {step} wacht op zijn dialoogvenster
@plural {n} action|{n} actions {n} handeling|{n} handelingen
+ Auto Add/Delete Automatisch toevoegen/verwijderen
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index fab352b28..4bf1a5588 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -3687,3 +3687,4 @@ curves Smooth Wygładź
Action playback stopped Odtwarzanie operacji zatrzymane
Step {step} is waiting for its dialog Krok {step} czeka na swoje okno dialogowe
@plural {n} action|{n} actions {n} operacja|{n} operacje|{n} operacji
+ Auto Add/Delete Automatyczne dodawanie/usuwanie
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index b7c0def32..f562d5738 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -3880,3 +3880,4 @@ layerLabel No Color Sem cor
Action playback stopped Reprodução da ação interrompida
Step {step} is waiting for its dialog A etapa {step} está aguardando sua caixa de diálogo
@plural {n} action|{n} actions {n} ação|{n} ações
+ Auto Add/Delete Adicionar/excluir automaticamente
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 2f174fd7b..3e1fc3c39 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -3035,3 +3035,4 @@ curves Smooth Сгладить
Action playback stopped Воспроизведение операции остановлено
Step {step} is waiting for its dialog Шаг {step} ожидает своего диалога
@plural {n} action|{n} actions {n} операция|{n} операции|{n} операций
+ Auto Add/Delete Автодобавление/удаление
diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv
index e9dc17d8d..c67ccd013 100644
--- a/crates/ui-egui/src/i18n/tr.tsv
+++ b/crates/ui-egui/src/i18n/tr.tsv
@@ -3822,3 +3822,4 @@ cameraData Lens Lens
Load settings from a Camera Raw .xmp file Ayarları bir Camera Raw .xmp dosyasından yükle
Loaded Camera Raw settings from {file} Camera Raw ayarları {file} dosyasından yüklendi
Loaded Camera Raw settings from {file} ({n} not supported) Camera Raw ayarları {file} dosyasından yüklendi ({n} desteklenmiyor)
+ Auto Add/Delete Otomatik Ekle/Sil
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index 0facb9e9c..87562df81 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -3788,3 +3788,4 @@ curves Smooth Згладити
Action playback stopped Відтворення операції зупинено
Step {step} is waiting for its dialog Крок {step} очікує на свій діалог
@plural {n} action|{n} actions {n} операція|{n} операції|{n} операцій
+ Auto Add/Delete Автододавання/видалення
diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv
index 03ad654f7..5157c3d46 100644
--- a/crates/ui-egui/src/i18n/vi.tsv
+++ b/crates/ui-egui/src/i18n/vi.tsv
@@ -3574,3 +3574,4 @@ curves Smooth Làm mượt
Gradient Preset Options Tùy chọn thiết lập sẵn chuyển sắc
Import .GRD Nhập .GRD
Choose a gradient file (.grd). Chọn tệp chuyển sắc (.grd).
+ Auto Add/Delete Tự động thêm/xóa
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 080a5ac03..4fb92c2eb 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -2695,3 +2695,4 @@ curves Smooth 平滑
Action playback stopped 动作播放已停止
Step {step} is waiting for its dialog 步骤 {step} 正在等待其对话框
@plural {n} action|{n} actions {n} 个动作
+ Auto Add/Delete 自动添加/删除
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 3ed91649c..c3010b7ed 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -2680,3 +2680,4 @@ curves Smooth 平滑
Action playback stopped 動作播放已停止
Step {step} is waiting for its dialog 步驟 {step} 正在等待其對話框
@plural {n} action|{n} actions {n} 個動作
+ Auto Add/Delete 自動增加/刪除
diff --git a/crates/ui-egui/src/pen_draw_tests.rs b/crates/ui-egui/src/pen_draw_tests.rs
index 229d69995..2b3819ced 100644
--- a/crates/ui-egui/src/pen_draw_tests.rs
+++ b/crates/ui-egui/src/pen_draw_tests.rs
@@ -139,7 +139,9 @@ fn dragging_on_the_first_anchor_closes_with_its_handles_in_one_step() {
assert!(near([k.in_ctrl.x, k.in_ctrl.y], [0.0, 40.0]) && near([k.out_ctrl.x, k.out_ctrl.y], [40.0, 0.0]), "{k:?}");
assert!(k.smooth);
- // A plain click on a smooth first anchor closes without touching its handles.
+ // A plain click on a smooth first anchor closes without touching its handles. This path is
+ // drawn over the anchors of the one just finished, which Auto Add/Delete would delete (#4144).
+ h.state_mut().ui.tool_options.pen_auto_add_delete = false;
drag(&mut h, &[[20.0, 20.0], [40.0, 20.0]], None);
click(&mut h, [120.0, 20.0]);
click(&mut h, [120.0, 100.0]);
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index 620adf8d2..0e3424f25 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -588,6 +588,10 @@ pub struct ToolOptions {
/// Freeform Pen › Curve Fit: how far (px) the fitted path may stray from the pointer trace.
#[serde(default = "default_curve_fit")]
pub curve_fit: f32,
+ /// Pen › Auto Add/Delete: a Pen click on a segment of the active path adds an anchor there,
+ /// on one of its anchors deletes it (#4144).
+ #[serde(default = "yes")]
+ pub pen_auto_add_delete: bool,
/// Marquee options bar: "normal" | "fixedRatio" | "fixedSize", with the ratio or size.
#[serde(default = "default_marquee_style")]
pub marquee_style: String,
@@ -800,6 +804,7 @@ impl Default for ToolOptions {
polygon_sides: 5,
line_weight: 3.0,
curve_fit: default_curve_fit(),
+ pen_auto_add_delete: true,
marquee_style: default_marquee_style(),
marquee_width: 1.0,
marquee_height: 1.0,
diff --git a/crates/ui-egui/src/tool_feedback.rs b/crates/ui-egui/src/tool_feedback.rs
index bc993a7ae..eda03b305 100644
--- a/crates/ui-egui/src/tool_feedback.rs
+++ b/crates/ui-egui/src/tool_feedback.rs
@@ -105,6 +105,10 @@ pub fn badge(app: &PhotocraftApp, tool: Tool, m: egui::Modifiers) -> Option<Badg
if let Some(t) = crate::anchor_tools::effective(tool, m) {
return (!m.command).then_some(if t == Tool::AddAnchorPoint { Badge::Add } else { Badge::Subtract });
}
+ // The Pen over the active path with Auto Add/Delete on: what a click would do (#4144).
+ if let Some(p) = app.hover_doc.filter(|_| tool == Tool::Pen) {
+ return crate::anchor_tools::pen_auto(app, tool, m, p).map(|(t, ..)| if t == Tool::AddAnchorPoint { Badge::Add } else { Badge::Subtract });
+ }
if !is_selection_tool(tool) {
return None;
}
diff --git a/crates/ui-egui/src/tool_reset.rs b/crates/ui-egui/src/tool_reset.rs
index 8743fc105..9c97cd640 100644
--- a/crates/ui-egui/src/tool_reset.rs
+++ b/crates/ui-egui/src/tool_reset.rs
@@ -161,7 +161,8 @@ pub fn reset_options(o: &mut ToolOptions, tool: Tool) {
Tool::Smudge => reset!(strength, sample_all_layers, finger_painting),
Tool::Dodge | Tool::Burn => reset!(tone_range, exposure, protect_tones),
Tool::Sponge => reset!(sponge_mode, vibrance),
- Tool::Pen | Tool::CurvaturePen => reset!(vector_mode),
+ Tool::Pen => reset!(vector_mode, pen_auto_add_delete),
+ Tool::CurvaturePen => reset!(vector_mode),
Tool::FreeformPen => reset!(vector_mode, curve_fit),
Tool::Rectangle | Tool::EllipseShape | Tool::Triangle | Tool::Polygon | Tool::Line | Tool::CustomShape => {
reset!(vector_mode, shape_fill, stroke_width, shape_stroke, corner_radius, polygon_sides, line_weight)
diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rs
index d4de24920..63d12fb19 100644
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@ -887,6 +887,8 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform
if let Some((_, p)) = targeted_vector_mask(app) {
draw_path(&p, tool == Tool::PathSelection);
}
+ // The segment the Pen's Auto Add/Delete would add an anchor to, or the anchor it would delete.
+ crate::anchor_tools::draw_pen_hover(app, painter, &to_scr, accent, painter.ctx().input(|i| i.modifiers));
}
// Pen path in progress, with handles of the last knot and a rubber band to the pointer.
if let Some(pen) = &app.ui.pen {
@@ -1000,6 +1002,10 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
o.stroke_width = enabled_stroke_width(o.stroke_width);
}
}
+ if tool == Tool::Pen {
+ crate::widgets::vline(ui, 22.0);
+ crate::widgets::checkbox(ui, &mut o.pen_auto_add_delete, tl!("Auto Add/Delete"));
+ }
let enter = crate::shortcuts::pretty("Enter");
match tool {
Tool::FreeformPen => {
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 33fb8b319..d48af3bfc 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-12 · **Change:** minor (⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -118,6 +118,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
|---|---|---|
| Click corner, drag smooth, ⌥ breaks a handle, ⌘ direct-selects, ⇧ 45° | partial | TOOL-214-10 |
| Handle on the last point, close-drag handle | partial | #1482 |
+| Pen Auto Add/Delete: click a segment of the active path to add, an anchor to delete; ⇧ suspends it | done | #4144 |
| Path operations in the options bar (combine, subtract, intersect, exclude) | partial | `layer.combineShapes.*`; Pen options #1397 |
| On-canvas corner-radius handles on live shapes | missing | TOOL-214-12 |
| Shape stroke controls (dash, caps, joins, align) | done | TOOL-1053-1, [`shape-strokes.md`](shape-strokes.md) |
@@ -222,3 +223,4 @@ Paragraph; the rest open as in-app floating windows.
| 2026-10-11 | minor | Tool keys from Photoshop's shortcut set: ← / → rotate the brush tip, ⇧-click for new type, Space+F canvas colour |
| 2026-10-11 | minor | Spring-loaded tool letters done (#2672): holding any tool letter (Z included) past 300 ms, or using the canvas while it is down, makes the tool temporary until release |
| 2026-10-11 | minor | Type formatting keys done: ⇧⌘K, U, B, I and /, ⌥↑/↓, ⇧⌥↑/↓, ⌥←/→ over a selection and ⌥⇧⌘H format the selected type while editing, and no longer reach Color Settings, Desaturate, Auto Color or Inverse |
+| 2026-10-12 | minor | Pen Auto Add/Delete on the active path, with its options-bar checkbox, hover feedback and + / − cursor badge (#4144) |