mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 17:37:14 +00:00
Merge approved PhotoCraft PR #9504: fix(ui): Keyboard Shortcuts records ⌘Z instead of undoing the capture
This commit is contained in:
commit
735167d2bf
2 files changed
+39
-5
No files matched your search
@@ -101,17 +101,30 @@ 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;
|
||||
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 (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() {
|
||||
if let Some(step) = take_step(ctx) {
|
||||
|
||||
@@ -200,6 +200,27 @@ 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");
|
||||
// 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]
|
||||
fn ctrl_k_is_recorded_as_ctrl_k_not_the_control_key() {
|
||||
for ppp in [1.0, 2.0] {
|
||||
|
||||
Reference in new issue
Block a user