From 6df2884b5554e2019711671cd6717617572df7b5 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 11:23:58 -0600 Subject: [PATCH 1/2] fix(ui): Keyboard Shortcuts records Cmd+Z instead of undoing the capture (#9487) The dialog's own Cmd+Z history (#4697) took Cmd+Z while a shortcut field waited for keys and undid the click that started the capture, so Cmd+Z could never be bound. While a field captures, Cmd+Z now reaches it like any other key; outside a capture it still steps the dialog back, and a step back no longer leaves a field waiting for keys. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/edit_history.rs | 8 +++++++- crates/ui-egui/src/shortcut_capture_tests.rs | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/edit_history.rs b/crates/ui-egui/src/edit_history.rs index 2012f912c7..0f9f7d40c9 100644 --- a/crates/ui-egui/src/edit_history.rs +++ b/crates/ui-egui/src/edit_history.rs @@ -101,7 +101,9 @@ pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) { return; } if let Some(top) = app.ui.dialogs.last() { - if top.kind != DialogKind::Command { + // A shortcut field waiting for keys (Keyboard Shortcuts) records ⌘Z like any other key + // (#9487); stepping back here undid the click that started the capture. + if top.kind != DialogKind::Command || top.fields.get("capture").and_then(Value::as_bool) == Some(true) { return; } let id = top.id; @@ -112,6 +114,10 @@ pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) { { d.fields.retain(|k, _| k.starts_with("__")); d.fields.extend(now); + // A step back to before a recorded shortcut doesn't wait for keys again. + if let Some(c) = d.fields.get_mut("capture") { + *c = Value::Bool(false); + } } } else if let Some(d) = app.distort.gallery.as_mut() { if let Some(step) = take_step(ctx) { diff --git a/crates/ui-egui/src/shortcut_capture_tests.rs b/crates/ui-egui/src/shortcut_capture_tests.rs index c7853067aa..445c389931 100644 --- a/crates/ui-egui/src/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/shortcut_capture_tests.rs @@ -200,6 +200,21 @@ fn shift_is_recorded_when_modifier_key_events_carry_no_bits() { assert_eq!(field(&h, id, "capture"), json!(false)); } +/// ⌘Z can be bound like any other key (#9487): while a field waits for keys it is the shortcut +/// to record, not the dialog's own Undo (#4697), which used to undo the click that started the +/// capture. Once recorded, ⌘Z steps the dialog back again. +#[test] +fn cmd_z_is_recorded_while_capturing_and_undoes_otherwise() { + let (mut h, id) = dialog(1.0, "edit.search", "search…"); + capture(&mut h, &crate::shortcuts::pretty("Cmd+F"), Key::ControlLeft, Modifiers::COMMAND, Key::Z); + assert_eq!(field(&h, id, "overrides")["edit.search"], json!("Cmd+Z")); + assert_eq!(field(&h, id, "capture"), json!(false)); + key(&mut h, Key::Z, true, Modifiers::COMMAND); + h.run_steps(2); + assert_ne!(field(&h, id, "overrides")["edit.search"], json!("Cmd+Z"), "⌘Z outside a capture undoes the change"); + assert_eq!(field(&h, id, "capture"), json!(false), "and doesn't wait for keys again"); +} + #[test] fn ctrl_k_is_recorded_as_ctrl_k_not_the_control_key() { for ppp in [1.0, 2.0] { From 993c9ed167c6acd9bc8f87c6cff6e2c7abba17a8 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 25 Oct 2026 11:56:29 -0600 Subject: [PATCH 2/2] Dialog undo: clearing a restored capture keeps Redo CodeRabbit on #9504 (inline 4371715685): when Undo restored settings with capture on, the reset to off (and the dialog then dropping its capture modifiers) differed from the step's settled settings, so the next frame recorded it as a new edit and cleared Redo. The reset now also drops captureMods, as the dialog does, and updates the settled settings. Test: cmd_z_is_recorded_while_capturing_and_undoes_otherwise (adds Redo) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/edit_history.rs | 19 +++++++++++++------ crates/ui-egui/src/shortcut_capture_tests.rs | 6 ++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/edit_history.rs b/crates/ui-egui/src/edit_history.rs index 0f9f7d40c9..d122c4b440 100644 --- a/crates/ui-egui/src/edit_history.rs +++ b/crates/ui-egui/src/edit_history.rs @@ -108,15 +108,22 @@ pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) { } let id = top.id; let mut now = settings(&top.fields); + let history = app.dialog_edits.entry(id).or_insert_with(|| EditHistory::new(&now)); if let Some(step) = take_step(ctx) - && app.dialog_edits.entry(id).or_insert_with(|| EditHistory::new(&now)).step(&mut now, step) - && let Some(d) = app.ui.dialog_mut(id) + && history.step(&mut now, step) { - d.fields.retain(|k, _| k.starts_with("__")); - d.fields.extend(now); - // A step back to before a recorded shortcut doesn't wait for keys again. - if let Some(c) = d.fields.get_mut("capture") { + // A step back to before a recorded shortcut doesn't wait for keys again (and, like + // the dialog itself, keeps no capture modifiers then). That isn't an edit of its own: + // the step's settled settings say so too, or the next frame would record it and + // lose Redo. + if let Some(c) = now.get_mut("capture") { *c = Value::Bool(false); + now.remove("captureMods"); + history.settled = now.clone(); + } + if let Some(d) = app.ui.dialog_mut(id) { + d.fields.retain(|k, _| k.starts_with("__")); + d.fields.extend(now); } } } else if let Some(d) = app.distort.gallery.as_mut() { diff --git a/crates/ui-egui/src/shortcut_capture_tests.rs b/crates/ui-egui/src/shortcut_capture_tests.rs index 445c389931..f59bf278e8 100644 --- a/crates/ui-egui/src/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/shortcut_capture_tests.rs @@ -213,6 +213,12 @@ fn cmd_z_is_recorded_while_capturing_and_undoes_otherwise() { h.run_steps(2); assert_ne!(field(&h, id, "overrides")["edit.search"], json!("Cmd+Z"), "⌘Z outside a capture undoes the change"); assert_eq!(field(&h, id, "capture"), json!(false), "and doesn't wait for keys again"); + // CodeRabbit on #9504: clearing the restored capture isn't a new edit, so Redo still works. + h.run_steps(2); + key(&mut h, Key::Z, true, Modifiers::COMMAND | Modifiers::SHIFT); + h.run_steps(2); + assert_eq!(field(&h, id, "overrides")["edit.search"], json!("Cmd+Z"), "⇧⌘Z redoes the recorded shortcut"); + assert_eq!(field(&h, id, "capture"), json!(false)); } #[test]