mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Esc deselects when no active operation needs cancelling (#2765)
* Esc deselects when no active operation needs cancelling (#2674) * Esc: keep the selection while a canvas drag is in progress Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: highperfocused <[email protected]> Co-authored-by: Brandon Thomas <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2 files changed
+68
No files matched your search
@@ -651,3 +651,45 @@ fn esc_ends_a_pen_path_and_keeps_it() {
|
||||
assert_eq!(path.subpaths[0].knots.len(), 3);
|
||||
assert_eq!(h.state().ui.selected_path.as_deref(), Some("work"));
|
||||
}
|
||||
|
||||
/// Esc with no active operation deselects (#2674), like ⌘D.
|
||||
#[test]
|
||||
fn escape_deselects_when_nothing_else_needs_cancelling() {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("select.all", json!({})).unwrap();
|
||||
h.run_steps(1);
|
||||
assert!(h.state().session.active().unwrap().doc.selection.is_some());
|
||||
h.key_press(Key::Escape);
|
||||
h.run_steps(2);
|
||||
assert!(h.state().session.active().unwrap().doc.selection.is_none(), "Esc deselects");
|
||||
assert!(!h.state().ui.status_error, "no error: {}", h.state().ui.status);
|
||||
// With nothing selected, Esc stays untouched (no history step, no error).
|
||||
let steps = h.state().session.active().unwrap().history.entries().len();
|
||||
h.key_press(Key::Escape);
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().session.active().unwrap().history.entries().len(), steps, "no Deselect step");
|
||||
}
|
||||
|
||||
/// The dialog owns Esc: it cancels the dialog and the selection stays.
|
||||
#[test]
|
||||
fn escape_with_a_dialog_open_cancels_the_dialog_not_the_selection() {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("select.all", json!({})).unwrap();
|
||||
open_dialog(&mut h);
|
||||
h.key_press(Key::Escape);
|
||||
h.run_steps(2);
|
||||
assert!(h.state().ui.dialogs.is_empty(), "Esc cancelled the dialog");
|
||||
assert!(h.state().session.active().unwrap().doc.selection.is_some(), "the selection stays");
|
||||
}
|
||||
|
||||
/// The command palette owns Esc: it closes the palette and the selection stays.
|
||||
#[test]
|
||||
fn escape_with_the_palette_open_does_not_deselect() {
|
||||
let mut h = harness();
|
||||
h.state_mut().run("select.all", json!({})).unwrap();
|
||||
h.state_mut().ui.palette_open = true;
|
||||
h.run_steps(1);
|
||||
h.key_press(Key::Escape);
|
||||
h.run_steps(2);
|
||||
assert!(h.state().session.active().unwrap().doc.selection.is_some(), "Esc belongs to the palette");
|
||||
}
|
||||
@@ -451,6 +451,32 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Esc with no active operation deselects (#2674), like ⌘D. The key is only taken when a
|
||||
// selection exists, and never from a state that handles Esc later in the frame: menus,
|
||||
// dialogs and inline type returned above, transform, pen, lasso and crop consumed it, and
|
||||
// these own theirs: full screen (Esc returns), the palette, the canvas and layer menus, the
|
||||
// brush picker, Rotate View, Adaptive Wide Angle, the Filter Gallery, the TIFF prompt, any
|
||||
// open egui popup and the toolbar tool flyout. A canvas drag in progress (a marquee being
|
||||
// drawn) keeps the selection too.
|
||||
let esc_taken = app.ui.view.hides_chrome()
|
||||
|| app.drag.is_some()
|
||||
|| app.ui.palette_open
|
||||
|| app.ui.canvas_tool_menu.is_some()
|
||||
|| app.ui.layer_menu.is_some()
|
||||
|| app.ui.brush_picker.is_some()
|
||||
|| app.ui.tool == Tool::RotateView
|
||||
|| app.wide_angle.is_some()
|
||||
|| app.tiff_options.is_some()
|
||||
|| app.distort.gallery.is_some()
|
||||
|| ctx.any_popup_open()
|
||||
|| ctx.data(|d| d.get_temp::<(egui::Id, egui::Rect)>(egui::Id::new("tool-flyout")).is_some());
|
||||
if !esc_taken && app.session.active().is_some_and(|st| st.doc.selection.is_some()) && pressed(Key::Escape) {
|
||||
if let Err(e) = app.run("select.deselect", json!({})) {
|
||||
app.ui.status = e;
|
||||
app.ui.status_error = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Tool keys; pressing the key of the current group cycles within it. With Preferences ›
|
||||
// Tools › Use Shift Key for Tool Switch, only ⇧+key cycles and the plain key keeps the
|
||||
// group's current tool. From another group, the key picks the group's last-used tool.
|
||||
|
||||
Reference in new issue
Block a user