diff --git a/crates/ui-egui/src/input/shortcuts.rs b/crates/ui-egui/src/input/shortcuts.rs index 158079ddf0..26f846d7bc 100644 --- a/crates/ui-egui/src/input/shortcuts.rs +++ b/crates/ui-egui/src/input/shortcuts.rs @@ -893,6 +893,9 @@ fn handle_escape_and_view_keys(app: &mut PhotocraftApp, ctx: &egui::Context) { // Rotate View, Adaptive Wide Angle, the Filter Gallery, the TIFF prompt, any open egui popup // and the toolbar tool and "…" flyouts. A canvas drag in progress (a marquee being drawn) keeps it too. let esc_taken = app.drag.is_some() + // A Direct Selection drag (a Cmd-drag on an anchor) never reaches `app.drag`: Esc must not + // leave full screen or deselect pixels while its release is still to come (#13072). + || (app.ui.tool == Tool::DeleteAnchorPoint && app.ui.direct_selection.drag.is_some()) || app.ui.palette_open || app.ui.canvas_tool_menu.is_some() || app.ui.layer_menu.is_some() @@ -921,22 +924,31 @@ fn handle_escape_and_view_keys(app: &mut PhotocraftApp, ctx: &egui::Context) { } return; } - // Delete Anchor Point (#12773): Esc first clears anchors selected on the saved path targeted in - // the Paths panel, then deselects that path, so clicks edit nothing. Not while its name is typed - // in the panel: egui has already dropped the field's focus, and the panel cancels on Esc. + // Delete Anchor Point (#12773): Esc first hides the anchors of the saved path targeted in the + // Paths panel, then deselects that path, so clicks edit nothing. The first Esc leaves the path + // targeted whether or not an anchor was selected (#13072), and clears only anchors selected on + // that path, never another path's. Not while its name is typed in the panel: egui has already + // dropped the field's focus, and the panel cancels on Esc. A Direct Selection drag keeps Esc + // away through `esc_taken` above, so its release still moves the anchors (#13072). if !esc_taken && app.ui.tool == Tool::DeleteAnchorPoint && !crate::vector_ui::path_renaming(app, ctx) && let Some((index, _)) = crate::vector_ui::selected_saved_path_index(app) { let ds = &app.ui.direct_selection; - let selected = ds.target == Some(crate::direct_select::PathRef::Saved(index)) && (!ds.anchors.is_empty() || ds.segment.is_some()); + let on_this_path = ds.target == Some(crate::direct_select::PathRef::Saved(index)); + let selected = on_this_path && (!ds.anchors.is_empty() || ds.segment.is_some()); if pressed(Key::Escape) { - if selected { - app.ui.direct_selection.anchors.clear(); - app.ui.direct_selection.segment = None; + // The stage belongs to this path: choosing another one starts at the first Esc again. + if selected || app.ui.direct_selection.escape_hidden != Some(index) { + if selected { + app.ui.direct_selection.anchors.clear(); + app.ui.direct_selection.segment = None; + } + app.ui.direct_selection.escape_hidden = Some(index); } else { app.ui.selected_path = None; + app.ui.direct_selection.escape_hidden = None; } return; } diff --git a/crates/ui-egui/src/tools/anchor_tools/delete_anchor_escape_tests.rs b/crates/ui-egui/src/tools/anchor_tools/delete_anchor_escape_tests.rs index 2fd81fdbd2..7513898191 100644 --- a/crates/ui-egui/src/tools/anchor_tools/delete_anchor_escape_tests.rs +++ b/crates/ui-egui/src/tools/anchor_tools/delete_anchor_escape_tests.rs @@ -9,7 +9,7 @@ use serde_json::json; use super::tests::{click, steps}; use crate::PhotocraftApp; -use crate::direct_select::{PathRef, active_paths, candidates}; +use crate::direct_select::{Drag, PathRef, active_paths, candidates}; use crate::state::Tool; /// The issue's document: 800 x 600 with the saved path "Path 1", a corner square with an anchor @@ -142,3 +142,43 @@ fn escape_while_renaming_path_1_cancels_the_rename() { assert_eq!(names, ["Path 1"], "Esc cancels the rename"); assert_eq!(h.state().ui.selected_path.as_deref(), Some("Path 1")); } + +#[test] +fn the_first_escape_without_a_selected_anchor_keeps_path_1_targeted() { + let mut app = app(); + let n = steps(&app); + escape(&mut app); + assert_eq!(app.ui.selected_path.as_deref(), Some("Path 1"), "the first Esc keeps Path 1 targeted"); + assert!(!active_paths(&app).is_empty(), "its outline stays"); + escape(&mut app); + assert_eq!(app.ui.selected_path, None, "the second Esc deselects Path 1"); + assert!(candidates(&app).is_empty(), "no outline or anchors are drawn"); + assert_eq!(steps(&app), n, "Esc adds no History step"); +} + +#[test] +fn an_escape_during_a_direct_selection_drag_keeps_the_anchors() { + let mut app = app(); + // Cmd is Direct Selection while held: it selects the anchor instead of deleting it. + click(&mut app, [300.0, 300.0], Modifiers::COMMAND); + assert_eq!(app.ui.direct_selection.anchors, vec![[0, 1]]); + app.ui.direct_selection.drag = Some(Drag::Marquee { start: [200.0, 200.0], end: [400.0, 400.0], add: false }); + escape(&mut app); + assert_eq!(app.ui.direct_selection.anchors, vec![[0, 1]], "the drag's release still moves them"); + assert!(app.ui.direct_selection.drag.is_some(), "and Esc does not end the drag"); + assert_eq!(app.ui.selected_path.as_deref(), Some("Path 1"), "nor deactivates the path"); +} + +#[test] +fn a_newly_targeted_path_starts_at_the_first_escape_again() { + let mut app = app(); + let line = json!({"subpaths": [{"knots": [[600, 100], [700, 100]]}]}); + app.run("path.set", json!({"name": "Path 2", "path": line})).unwrap(); + escape(&mut app); + assert_eq!(app.ui.selected_path.as_deref(), Some("Path 1"), "the first Esc keeps Path 1 targeted"); + app.ui.selected_path = Some("Path 2".into()); + escape(&mut app); + assert_eq!(app.ui.selected_path.as_deref(), Some("Path 2"), "the first Esc on a new path keeps it targeted"); + escape(&mut app); + assert_eq!(app.ui.selected_path, None, "and the second Esc deselects it"); +} diff --git a/crates/ui-egui/src/tools/direct_select.rs b/crates/ui-egui/src/tools/direct_select.rs index 9272d570fc..65c9d33b09 100644 --- a/crates/ui-egui/src/tools/direct_select.rs +++ b/crates/ui-egui/src/tools/direct_select.rs @@ -85,6 +85,10 @@ pub struct DirectSelection { pub(crate) owner: Option, #[serde(skip)] pub(crate) cancelled_drag: bool, + /// The saved path whose anchors the first Escape hid (#13072): the next Escape deactivates it, + /// and targeting another path starts at the first Escape again. + #[serde(skip)] + pub(crate) escape_hidden: Option, /// Path Selection only: the target path's [`crate::path_components::SelectionSignature`] when /// the selection was made — a structural identity that survives history revisions (a click /// activates the layer, colours change, components move), so the component selection lives