Merge pull request #13176 from Raghav2012Code/fix/13072-delete-anchor-escape-stage

Delete Anchor Point keeps its path on the first Escape, and leaves a drag alone (#13072)
This commit is contained in:
David Mann authored and GitHub committed 2026-11-12 02:19:30 +01:00
commit 35887692ff
3 files changed
+64 -8

No files matched your search

+19 -7
View File
@@ -895,6 +895,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()
@@ -923,22 +926,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;
}
@@ -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");
}
@@ -86,6 +86,10 @@ pub struct DirectSelection {
pub(crate) owner: Option<Owner>,
#[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<usize>,
/// 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