mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Delete Anchor Point: Delete with an anchor selected edits the path, never the layer (#12761)
The Delete Anchor Point tool with one anchor selected now takes the Add Anchor Point route (#12703): Delete and Backspace remove the anchor and its segments instead of falling through to Edit > Clear. When the anchor is the last one of its subpath, the whole subpath goes as one History step, Delete Selection (path.deleteAnchor with segments relabels its step; the tool click keeps Delete Anchor Point). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium
This commit is contained in:
1 parent
de9add28b2
commit
d3bc67c94b
6 files changed
+131
-9
No files matched your search
@@ -153,3 +153,21 @@ fn a_type_paths_last_anchor_is_still_refused() {
|
||||
assert_eq!(type_path(&s), Some(before));
|
||||
assert_eq!(s.active().unwrap().history.entries().len(), steps);
|
||||
}
|
||||
|
||||
/// ⌫ / Delete on the Delete Anchor Point tool's last anchor of a subpath among others (#12761)
|
||||
/// takes the subpath as one Delete Selection step; the tool's click keeps Delete Anchor Point.
|
||||
#[test]
|
||||
fn deleting_a_subpaths_last_anchor_with_its_segments_is_delete_selection() {
|
||||
let two = || json!({"subpaths": [{"closed": false, "knots": [[100, 300], [200, 300]]}, {"closed": false, "knots": [[400, 300]]}]});
|
||||
let s = &mut session();
|
||||
s.execute("path.set", json!({"name": "Path 1", "path": two()})).unwrap();
|
||||
let before = doc(s).paths[0].path.clone();
|
||||
let r = s.execute("path.deleteAnchor", json!({"name": "Path 1", "subpath": 1, "knot": 0, "segments": true})).unwrap();
|
||||
assert_eq!(r["subpathRemoved"], json!(true));
|
||||
assert_eq!(doc(s).paths[0].path.subpaths.len(), 1);
|
||||
assert_eq!(s.active().unwrap().history.undo_label(), Some("Delete Selection"));
|
||||
assert!(s.undo());
|
||||
assert_eq!(doc(s).paths[0].path, before);
|
||||
s.execute("path.deleteAnchor", json!({"name": "Path 1", "subpath": 1, "knot": 0})).unwrap();
|
||||
assert_eq!(s.active().unwrap().history.undo_label(), Some("Delete Anchor Point"), "the click's label is unchanged");
|
||||
}
|
||||
@@ -192,6 +192,14 @@ fn delete_anchor(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
Ok(())
|
||||
})?;
|
||||
// Delete / Backspace (`segments`) that takes a whole subpath is Delete Selection, as in
|
||||
// Photoshop (#12761); the tool's click on a lone anchor stays Delete Anchor Point.
|
||||
if removed
|
||||
&& segments
|
||||
&& let Some(st) = s.active_mut()
|
||||
{
|
||||
st.history.set_current_label("Delete Selection");
|
||||
}
|
||||
if let Some(o) = r.as_object_mut() {
|
||||
o.insert("subpathRemoved".into(), json!(removed));
|
||||
}
|
||||
|
||||
@@ -195,3 +195,5 @@ mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod add_anchor_delete_key_tests;
|
||||
#[cfg(test)]
|
||||
mod delete_anchor_delete_key_tests;
|
||||
@@ -11,7 +11,7 @@ use crate::state::Tool;
|
||||
|
||||
/// 800 x 600 on white, pixel layer Red active, saved path Path 1 (a closed corner square)
|
||||
/// targeted in the Paths panel, the Add Anchor Point tool on.
|
||||
fn app() -> PhotocraftApp {
|
||||
pub(super) fn app() -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.session.execute("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap();
|
||||
app.sync_views();
|
||||
@@ -23,25 +23,25 @@ fn app() -> PhotocraftApp {
|
||||
app
|
||||
}
|
||||
|
||||
fn path1(app: &PhotocraftApp) -> Path {
|
||||
pub(super) fn path1(app: &PhotocraftApp) -> Path {
|
||||
app.session.active().unwrap().doc.paths.iter().find(|p| p.name == "Path 1").unwrap().path.clone()
|
||||
}
|
||||
|
||||
fn layers(app: &PhotocraftApp) -> usize {
|
||||
pub(super) fn layers(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().doc.layers.len()
|
||||
}
|
||||
|
||||
fn steps(app: &PhotocraftApp) -> usize {
|
||||
pub(super) fn steps(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
fn ctrl_click(app: &mut PhotocraftApp, at: [f64; 2]) {
|
||||
pub(super) fn ctrl_click(app: &mut PhotocraftApp, at: [f64; 2]) {
|
||||
tool_event(app, ToolEvent::Down { x: at[0], y: at[1], pressure: 1.0 }, Modifiers::COMMAND);
|
||||
tool_event(app, ToolEvent::Up { x: at[0], y: at[1] }, Modifiers::COMMAND);
|
||||
}
|
||||
|
||||
/// A key through the app's shortcut handling, as the canvas gets it.
|
||||
fn press(app: &mut PhotocraftApp, key: egui::Key) {
|
||||
pub(super) fn press(app: &mut PhotocraftApp, key: egui::Key) {
|
||||
let ctx = egui::Context::default();
|
||||
let m = Modifiers::NONE;
|
||||
let raw = egui::RawInput {
|
||||
@@ -53,7 +53,7 @@ fn press(app: &mut PhotocraftApp, key: egui::Key) {
|
||||
ctx.end_pass().textures_delta.clear();
|
||||
}
|
||||
|
||||
fn anchors(path: &Path) -> Vec<[f64; 2]> {
|
||||
pub(super) fn anchors(path: &Path) -> Vec<[f64; 2]> {
|
||||
path.subpaths.iter().flat_map(|sp| sp.knots.iter().map(|k| [k.anchor.x, k.anchor.y])).collect()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
//! #12761: with the Delete Anchor Point tool, Delete / Backspace on a selected anchor edits the
|
||||
//! path, never the active layer. The single anchor left of a subpath takes the whole subpath
|
||||
//! (History: Delete Selection); an anchor of a longer subpath goes as in #12703.
|
||||
|
||||
use egui::Modifiers;
|
||||
use serde_json::json;
|
||||
|
||||
use super::add_anchor_delete_key_tests::{anchors, app as add_app, ctrl_click, layers, path1, press, steps};
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
use crate::state::Tool;
|
||||
|
||||
/// The measured document: Path 1 holds a square, the open line B (400,300) to (700,300) and an
|
||||
/// S-curve; the Delete Anchor Point tool is on.
|
||||
fn app() -> PhotocraftApp {
|
||||
let mut app = add_app();
|
||||
let path = json!({"subpaths": [
|
||||
{"closed": true, "knots": [[100, 100], [200, 100], [200, 200], [100, 200]]},
|
||||
{"closed": false, "knots": [[400, 300], [700, 300]]},
|
||||
{"closed": false, "knots": [[100, 400], [150, 350], [200, 450], [250, 400]]},
|
||||
]});
|
||||
app.run("path.set", json!({"name": "Path 1", "path": path})).unwrap();
|
||||
app.ui.tool = Tool::DeleteAnchorPoint;
|
||||
app
|
||||
}
|
||||
|
||||
fn click(app: &mut PhotocraftApp, at: [f64; 2]) {
|
||||
tool_event(app, ToolEvent::Down { x: at[0], y: at[1], pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Up { x: at[0], y: at[1] }, Modifiers::NONE);
|
||||
}
|
||||
|
||||
/// B's end deleted by a click, then B's last anchor selected.
|
||||
fn with_lone_anchor_selected() -> PhotocraftApp {
|
||||
let mut app = app();
|
||||
click(&mut app, [700.0, 300.0]);
|
||||
ctrl_click(&mut app, [400.0, 300.0]);
|
||||
assert_eq!(app.ui.direct_selection.anchors, vec![[1, 0]], "Ctrl+click selects B's last anchor");
|
||||
app
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_and_backspace_on_a_subpaths_last_anchor_remove_the_subpath_not_the_layer() {
|
||||
for key in [egui::Key::Delete, egui::Key::Backspace] {
|
||||
let mut app = with_lone_anchor_selected();
|
||||
let (before, n, count) = (path1(&app), steps(&app), layers(&app));
|
||||
assert_eq!(before.subpaths.len(), 3, "{key:?}: B is down to one anchor");
|
||||
press(&mut app, key);
|
||||
assert_eq!(layers(&app), count, "{key:?}: every layer is still there");
|
||||
assert_eq!(path1(&app).subpaths.len(), 2, "{key:?}: Path 1 keeps the square and the S-curve");
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!((st.history.past_len(), st.history.undo_label()), (n + 1, Some("Delete Selection")), "{key:?}");
|
||||
assert!(app.session.undo());
|
||||
assert_eq!(path1(&app), before, "{key:?}: Undo brings B back");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_on_an_anchor_of_a_longer_subpath_goes_as_for_add_anchor_point() {
|
||||
for key in [egui::Key::Delete, egui::Key::Backspace] {
|
||||
let mut app = app();
|
||||
let (before, n, count) = (path1(&app), steps(&app), layers(&app));
|
||||
ctrl_click(&mut app, [200.0, 200.0]);
|
||||
assert_eq!(app.ui.direct_selection.anchors, vec![[0, 2]], "{key:?}");
|
||||
press(&mut app, key);
|
||||
assert_eq!(layers(&app), count, "{key:?}: every layer is still there");
|
||||
let p = path1(&app);
|
||||
assert_eq!((p.subpaths.len(), p.subpaths[0].closed), (3, false), "{key:?}: the square opens");
|
||||
assert_eq!(anchors(&p).len(), 9, "{key:?}: one anchor fewer");
|
||||
let st = app.session.active().unwrap();
|
||||
assert_eq!((st.history.past_len(), st.history.undo_label()), (n + 1, Some("Delete Anchor Point")), "{key:?}");
|
||||
assert!(app.session.undo());
|
||||
assert_eq!(path1(&app), before, "{key:?}: Undo restores the square");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_selected_anchor_delete_keeps_its_usual_route() {
|
||||
let mut app = app();
|
||||
let before = path1(&app);
|
||||
press(&mut app, egui::Key::Delete);
|
||||
assert_eq!(path1(&app), before, "no anchor selected: the path stays");
|
||||
assert_ne!(app.session.active().unwrap().history.undo_label(), Some("Delete Selection"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_tools_keep_their_delete() {
|
||||
for tool in [Tool::Pen, Tool::FreeformPen, Tool::PathSelection] {
|
||||
let mut app = with_lone_anchor_selected();
|
||||
app.ui.tool = tool;
|
||||
let before = path1(&app);
|
||||
press(&mut app, egui::Key::Delete);
|
||||
assert_eq!(path1(&app), before, "{tool:?}: no anchor is deleted");
|
||||
}
|
||||
}
|
||||
@@ -216,14 +216,14 @@ pub(crate) fn delete_key_deletes_work_path(app: &PhotocraftApp) -> bool {
|
||||
&& matches!(target_path(app), Some((PathTarget::Work, _)))
|
||||
}
|
||||
|
||||
/// The anchor ⌫ / Delete removes, with its two segments: with the Add Anchor Point tool, the one
|
||||
/// The anchor ⌫ / Delete removes, with its two segments: with the Add or Delete Anchor Point tool, the one
|
||||
/// anchor selected on it (⌘/Ctrl+click) while that selection still holds and its path is shown,
|
||||
/// as in Photoshop (#12703). The key reached Edit › Clear and deleted the active layer. Several
|
||||
/// selected anchors weren't measured and keep the key's other routes.
|
||||
pub(crate) fn delete_key_deletes_anchor(app: &PhotocraftApp) -> Option<(crate::direct_select::PathRef, [usize; 2])> {
|
||||
let ds = &app.ui.direct_selection;
|
||||
let ([[s, k]], Some(target)) = (ds.anchors.as_slice(), ds.target) else { return None };
|
||||
let usable = app.ui.tool == Tool::AddAnchorPoint
|
||||
let usable = matches!(app.ui.tool, Tool::AddAnchorPoint | Tool::DeleteAnchorPoint)
|
||||
&& app.ui.pen.is_none()
|
||||
&& ds.drag.is_none()
|
||||
&& app.ui.view.shows(app.ui.view.show.target_path)
|
||||
|
||||
Reference in new issue
Block a user