mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge pull request #12995 from rmsff/fix/delete-anchor-escape-12773
Delete Anchor Point: Escape clears selected anchors, then the targeted path
This commit is contained in:
6 files changed
+175
-2
No files matched your search
@@ -913,6 +913,26 @@ 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.
|
||||
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());
|
||||
if pressed(Key::Escape) {
|
||||
if selected {
|
||||
app.ui.direct_selection.anchors.clear();
|
||||
app.ui.direct_selection.segment = None;
|
||||
} else {
|
||||
app.ui.selected_path = None;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// + / − pick a Path Operation with the Pen tools and Path Selection (`path_components`)…
|
||||
crate::path_components::handle_keys(app, ctx);
|
||||
// … and otherwise ⇧+ / ⇧− step the blend mode and ⇧⌥ letters pick one (`blend_keys`). Before the
|
||||
|
||||
@@ -195,3 +195,6 @@ mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod add_anchor_delete_key_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod delete_anchor_escape_tests;
|
||||
@@ -0,0 +1,144 @@
|
||||
//! #12773: with Delete Anchor Point, Esc first clears anchors selected on the saved path targeted
|
||||
//! in the Paths panel, then deselects that path, so its outline and anchors go and clicks delete
|
||||
//! nothing. Esc never adds a History step.
|
||||
|
||||
use egui::{Key, Modifiers, vec2};
|
||||
use egui_kittest::{Harness, kittest::Queryable};
|
||||
use photocraft_doc::vector::Path;
|
||||
use serde_json::json;
|
||||
|
||||
use super::tests::{click, steps};
|
||||
use crate::PhotocraftApp;
|
||||
use crate::direct_select::{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
|
||||
/// at (300, 300), targeted in the Paths panel.
|
||||
fn app() -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap();
|
||||
let square = json!({"subpaths": [{"closed": true, "knots": [[100, 300], [300, 300], [300, 500], [100, 500]]}]});
|
||||
app.run("path.set", json!({"name": "Path 1", "path": square})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.tool = Tool::DeleteAnchorPoint;
|
||||
app.ui.selected_path = Some("Path 1".into());
|
||||
app
|
||||
}
|
||||
|
||||
fn escape(app: &mut PhotocraftApp) {
|
||||
let ctx = egui::Context::default();
|
||||
let key = egui::Event::Key { key: Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE };
|
||||
ctx.begin_pass(egui::RawInput { events: vec![key], ..Default::default() });
|
||||
crate::shortcuts::handle(app, &ctx);
|
||||
ctx.end_pass().textures_delta.clear();
|
||||
}
|
||||
|
||||
fn path_1(app: &PhotocraftApp) -> Path {
|
||||
app.session.active().unwrap().doc.paths.iter().find(|p| p.name == "Path 1").unwrap().path.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_escapes_deselect_path_1_and_a_click_then_deletes_nothing() {
|
||||
let mut app = app();
|
||||
let (before, n) = (path_1(&app), steps(&app));
|
||||
escape(&mut app);
|
||||
escape(&mut app);
|
||||
assert_eq!(app.ui.selected_path, None, "Path 1 is no longer selected in the Paths panel");
|
||||
assert!(candidates(&app).is_empty(), "no outline or anchors are drawn");
|
||||
assert_eq!(steps(&app), n, "Esc adds no History step");
|
||||
click(&mut app, [300.0, 300.0], Modifiers::NONE);
|
||||
assert_eq!(path_1(&app), before);
|
||||
assert_eq!(steps(&app), n, "the click adds no History step");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_first_escape_clears_the_selected_anchor_and_the_second_deselects_the_path() {
|
||||
let mut app = app();
|
||||
// ⌘ 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.target, app.ui.direct_selection.anchors.clone()), (Some(PathRef::Saved(0)), vec![[0, 1]]));
|
||||
let n = steps(&app);
|
||||
escape(&mut app);
|
||||
assert!(app.ui.direct_selection.anchors.is_empty(), "the first Esc clears the anchor");
|
||||
assert_eq!(app.ui.selected_path.as_deref(), Some("Path 1"), "and keeps Path 1 selected");
|
||||
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_eq!(steps(&app), n);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_targeted_work_path_keeps_todays_escape() {
|
||||
let mut app = app();
|
||||
let line = json!({"subpaths": [{"knots": [[100, 100], [200, 100]]}]});
|
||||
app.run("path.set", json!({"name": "work", "path": line})).unwrap();
|
||||
app.ui.selected_path = Some("work".into());
|
||||
escape(&mut app);
|
||||
assert_eq!(app.ui.selected_path.as_deref(), Some("work"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn anchors_selected_on_a_shape_layer_keep_todays_escape() {
|
||||
let mut app = app();
|
||||
app.ui.selected_path = None;
|
||||
let id = app.run("shape.create", json!({"kind": "rect", "rect": [500, 100, 100, 100], "fill": "#3070c0"})).unwrap()["layer"].as_u64().unwrap();
|
||||
click(&mut app, [600.0, 200.0], Modifiers::COMMAND);
|
||||
let selected = (app.ui.direct_selection.target, app.ui.direct_selection.anchors.clone());
|
||||
assert_eq!(selected, (Some(PathRef::Layer(id)), vec![[0, 2]]));
|
||||
escape(&mut app);
|
||||
assert_eq!((app.ui.direct_selection.target, app.ui.direct_selection.anchors.clone()), selected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_path_1_targeted_escape_still_leaves_full_screen_and_deselects_pixels_first() {
|
||||
let mut app = app();
|
||||
app.ui.view.screen_mode = "fullScreen".into();
|
||||
escape(&mut app);
|
||||
assert_eq!(app.ui.view.screen_mode, "standard");
|
||||
assert_eq!(app.ui.selected_path.as_deref(), Some("Path 1"), "leaving full screen keeps Path 1 selected");
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
escape(&mut app);
|
||||
assert!(app.session.active().unwrap().doc.selection.is_none(), "Esc deselects the pixels");
|
||||
assert_eq!(app.ui.selected_path.as_deref(), Some("Path 1"), "and keeps Path 1 selected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_no_path_targeted_escape_still_leaves_full_screen_and_deselects_pixels() {
|
||||
let mut app = app();
|
||||
app.ui.selected_path = None;
|
||||
app.ui.view.screen_mode = "fullScreen".into();
|
||||
escape(&mut app);
|
||||
assert_eq!(app.ui.view.screen_mode, "standard");
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
escape(&mut app);
|
||||
assert!(app.session.active().unwrap().doc.selection.is_none());
|
||||
}
|
||||
|
||||
/// Esc while Path 1's name is typed in the Paths panel cancels the rename and keeps Path 1
|
||||
/// selected: egui drops the field's focus before the shortcuts run, so the step must wait.
|
||||
#[test]
|
||||
fn escape_while_renaming_path_1_cancels_the_rename() {
|
||||
let mut h = Harness::builder().with_size(vec2(1440.0, 900.0)).with_step_dt(1.0 / 60.0).with_max_steps(64).build_eframe(|cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
|
||||
let mut app = app();
|
||||
// Layers | Channels | Paths: the Paths tab.
|
||||
app.ui.dock_tabs.layers = 2;
|
||||
app
|
||||
});
|
||||
h.run_steps(8);
|
||||
let name = h.get_by_label("Path 1").rect().left_center() + vec2(60.0, 0.0);
|
||||
h.event(egui::Event::PointerMoved(name));
|
||||
h.run_steps(30);
|
||||
for pressed in [true, false, true, false] {
|
||||
h.event(egui::Event::PointerButton { pos: name, button: egui::PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
}
|
||||
h.run_steps(3);
|
||||
h.event(egui::Event::Text("Renamed".into()));
|
||||
h.run_steps(1);
|
||||
h.key_press(Key::Escape);
|
||||
h.run_steps(3);
|
||||
let names: Vec<String> = h.state().session.active().unwrap().doc.paths.iter().map(|p| p.name.clone()).collect();
|
||||
assert_eq!(names, ["Path 1"], "Esc cancels the rename");
|
||||
assert_eq!(h.state().ui.selected_path.as_deref(), Some("Path 1"));
|
||||
}
|
||||
@@ -34,11 +34,11 @@ fn work(app: &PhotocraftApp) -> Path {
|
||||
app.session.active().unwrap().doc.work_path.clone().unwrap()
|
||||
}
|
||||
|
||||
fn steps(app: &PhotocraftApp) -> usize {
|
||||
pub(super) fn steps(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.entries().len()
|
||||
}
|
||||
|
||||
fn click(app: &mut PhotocraftApp, at: [f64; 2], mods: Modifiers) {
|
||||
pub(super) fn click(app: &mut PhotocraftApp, at: [f64; 2], mods: Modifiers) {
|
||||
tool_event(app, ToolEvent::Down { x: at[0], y: at[1], pressure: 1.0 }, mods);
|
||||
tool_event(app, ToolEvent::Up { x: at[0], y: at[1] }, mods);
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ pub(crate) use path_ops::{
|
||||
};
|
||||
#[cfg(test)]
|
||||
use paths_panel::path_context_actions;
|
||||
pub(crate) use paths_panel::path_renaming;
|
||||
pub use paths_panel::{PathEntry, PathRow, path_rows, paths_footer, paths_panel};
|
||||
#[cfg(test)]
|
||||
pub(crate) use pen::over_first_anchor;
|
||||
|
||||
@@ -111,6 +111,11 @@ fn rename_id(doc: &Document) -> egui::Id {
|
||||
egui::Id::unique(("path-rename", doc.id.0))
|
||||
}
|
||||
|
||||
/// Is a path's name being typed in the active document's Paths panel? Esc belongs to its field.
|
||||
pub(crate) fn path_renaming(app: &PhotocraftApp, ctx: &egui::Context) -> bool {
|
||||
app.session.active().is_some_and(|st| ctx.data(|d| d.get_temp::<PathRename>(rename_id(&st.doc)).is_some()))
|
||||
}
|
||||
|
||||
/// Commands offered by a Paths row's context menu. The row's path is passed explicitly so a
|
||||
/// right-click acts on that row even when another path is selected in the panel. `layer` is the
|
||||
/// layer a `PathRow::Layer` row belongs to (the active layer).
|
||||
|
||||
Reference in new issue
Block a user