From a45699a4fe6516c0242a431c2efbaa623e9dcd55 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sun, 8 Nov 2026 15:03:19 -0500 Subject: [PATCH 1/3] Actions panel: a row dragged onto the trash is deleted, onto Create new action duplicated (#12373) The Actions panel rows carried a drag payload that only the reorder drop understood, so dropping a row on the footer trash or on Create new action did nothing. The footer buttons now take the drop (the trash deletes the dragged row, the plus duplicates it right after itself) through shared delete_row and duplicate_row helpers that also keep the selection and disclosure rows right, with a hover highlight and the same recording rules as the buttons. Tests drive real pointer drags for step and action rows onto both buttons, a drop on empty space, and a drop on the trash while recording. Co-Authored-By: Claude Sonnet 5.5 Model-Effort: Opus 5.5 drove and briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/panels/actions.rs | 82 ++++++++++++-- .../src/panels/actions/drag_drop_tests.rs | 105 ++++++++++++++++++ docs/ui-parity.md | 1 + 3 files changed, 177 insertions(+), 11 deletions(-) create mode 100644 crates/ui-egui/src/panels/actions/drag_drop_tests.rs diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index 73675c83f6..8c411f732f 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -1703,7 +1703,12 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result { return Ok(result); } let action = app.ui.actions.selected.ok_or_else(|| tl!("Select an action first").to_string())?; - let step = app.ui.actions.selected_step; + duplicate_row(app, action, app.ui.actions.selected_step) +} + +/// Duplicate one action or step (the selected row, or one dropped on Create new action, #12373) +/// and select the copy. +fn duplicate_row(app: &mut PhotocraftApp, action: usize, step: Option) -> Result { let count = app.session.actions.list.len(); let expanded = app.ui.actions.expanded.get(action).copied().unwrap_or(false); let result = app.run("actions.duplicate", json!({"action": action, "step": step}))?; @@ -1727,19 +1732,53 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result { fn delete_selection(app: &mut PhotocraftApp) { let Some(action) = app.ui.actions.selected else { return }; let step = app.ui.actions.selected_step; - let mut params = json!({"action": action}); - if let Some(step) = step { - params["step"] = json!(step); - } - if app.run("actions.delete", params).is_err() { + if !delete_row(app, action, step) { return; } // Clear selection after deletion so a second click cannot delete a different // step or unexpectedly fall back to deleting the entire action. app.ui.actions.selected = None; app.ui.actions.selected_step = None; - if step.is_none() && action < app.ui.actions.expanded.len() { - app.ui.actions.expanded.remove(action); +} + +/// Delete one action or step (the selected row, or one dropped on the trash, #12373) and keep +/// the selection and disclosure rows pointing at the same rows. False when the engine refused. +fn delete_row(app: &mut PhotocraftApp, action: usize, step: Option) -> bool { + let mut params = json!({"action": action}); + if let Some(step) = step { + params["step"] = json!(step); + } + if app.run("actions.delete", params).is_err() { + return false; + } + let ui = &mut app.ui.actions; + match (step, ui.selected) { + (None, Some(sel)) if sel == action => { + ui.selected = None; + ui.selected_step = None; + } + (None, Some(sel)) if sel > action => ui.selected = Some(sel - 1), + (Some(step), Some(sel)) if sel == action => match ui.selected_step { + Some(s) if s == step => { + ui.selected = None; + ui.selected_step = None; + } + Some(s) if s > step => ui.selected_step = Some(s - 1), + _ => {} + }, + _ => {} + } + if step.is_none() && action < ui.expanded.len() { + ui.expanded.remove(action); + } + true +} + +/// Outline a footer button a dragged row would be dropped on. +fn drop_target_highlight(ui: &egui::Ui, response: &egui::Response, active: bool, t: &Tokens) { + if active && response.contains_pointer() { + ui.painter().rect_filled(response.rect, t.radius_sm, t.hover); + ui.painter().rect_stroke(response.rect, t.radius_sm, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside); } } @@ -2153,16 +2192,34 @@ pub fn panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { app.ui.status = e; app.ui.status_error = true; } - if crate::icons::button(ui, "plus", 24.0, false, tl!("Create new action")).clicked() && !recording_now { + let dragged = egui::DragAndDrop::payload::(ui.ctx()).map(|row| *row); + let plus = crate::icons::button(ui, "plus", 24.0, false, tl!("Create new action")); + if plus.clicked() && !recording_now { begin_recording(app, false); } + // A row dragged onto Create new action is duplicated, as in Photoshop (#12373). + drop_target_highlight(ui, &plus, dragged.is_some() && !recording_now, &t); + if !recording_now + && let Some(row) = plus.dnd_release_payload::() + && let Err(e) = duplicate_row(app, row.action, row.step) + { + app.ui.status = e; + app.ui.status_error = true; + } let can_delete = app.ui.actions.selected.is_some() && (!recording_now || app.ui.actions.selected_step.is_some()); - ui.add_enabled_ui(can_delete, |ui| { + // While recording only a step may be deleted, by the button or by a drop. + let can_drop = dragged.is_some_and(|row| !recording_now || row.step.is_some()); + ui.add_enabled_ui(can_delete || can_drop, |ui| { let response = crate::icons::button(ui, "trash", 24.0, false, tl!("Delete")); - response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, can_delete, tl!("Delete"))); + response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, can_delete || can_drop, tl!("Delete"))); if response.clicked() { delete_selection(app); } + // A row dragged onto the trash is deleted without a confirmation (#12373). + drop_target_highlight(ui, &response, can_drop, &t); + if can_drop && let Some(row) = response.dnd_release_payload::() { + delete_row(app, row.action, row.step); + } }); let mode_label = if app.ui.actions.button_mode { tl!("Button Mode On") } else { tl!("Button Mode") }; let mode_button = ui.add_enabled(!recording_now, egui::Button::new(mode_label).small()).on_hover_text(tl!("Button Mode")); @@ -2293,3 +2350,6 @@ mod stop_tests; #[cfg(test)] mod playback_tests; + +#[cfg(test)] +mod drag_drop_tests; diff --git a/crates/ui-egui/src/panels/actions/drag_drop_tests.rs b/crates/ui-egui/src/panels/actions/drag_drop_tests.rs new file mode 100644 index 0000000000..2b0268b9f9 --- /dev/null +++ b/crates/ui-egui/src/panels/actions/drag_drop_tests.rs @@ -0,0 +1,105 @@ +//! #12373: an Actions panel row dragged onto the trash is deleted, onto Create new action duplicated. +use super::*; +use egui_kittest::{Harness, kittest::Queryable}; + +fn names(app: &PhotocraftApp) -> Vec { + app.session.actions.list.iter().map(|a| a.name.clone()).collect() +} + +fn steps(app: &PhotocraftApp, action: usize) -> Vec { + app.session.actions.list[action].steps.iter().map(|s| s.0.clone()).collect() +} + +fn harness() -> Harness<'static, PhotocraftApp> { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.session.actions.list.push(Action { + name: "First".into(), + steps: vec![("view.zoomOut".into(), json!({})), ("view.fitOnScreen".into(), json!({})), ("view.actualPixels".into(), json!({}))], + ..Default::default() + }); + app.session.actions.list.push(Action { name: "Second".into(), steps: vec![("view.zoomIn".into(), json!({}))], ..Default::default() }); + app.ui.actions.expanded = vec![true, false]; + let mut h = Harness::builder().with_size(vec2(320.0, 400.0)).build_ui_state(|ui, app| panel(app, ui), app); + h.run_steps(4); + h +} + +fn drag(h: &mut Harness<'_, PhotocraftApp>, from: egui::Pos2, to: egui::Pos2) { + h.event(egui::Event::PointerMoved(from)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE }); + h.run_steps(1); + h.event(egui::Event::PointerMoved(from + vec2(10.0, 0.0))); + h.run_steps(2); + h.event(egui::Event::PointerMoved(to)); + h.run_steps(2); + h.event(egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE }); + h.run_steps(3); +} + +fn center(h: &Harness<'_, PhotocraftApp>, label: &str) -> egui::Pos2 { + h.get_by_label(label).rect().center() +} + +#[test] +fn step_dragged_onto_trash_deletes_only_that_step() { + let mut h = harness(); + let (from, to) = (center(&h, "Fit on Screen"), center(&h, "Delete")); + drag(&mut h, from, to); + assert_eq!(names(h.state()), ["First", "Second"]); + assert_eq!(steps(h.state(), 0), ["view.zoomOut", "view.actualPixels"]); +} + +#[test] +fn action_dragged_onto_trash_is_deleted_even_when_another_is_selected() { + let mut h = harness(); + h.state_mut().ui.actions.select(1, None); + h.run_steps(2); + let (from, to) = (center(&h, "First"), center(&h, "Delete")); + drag(&mut h, from, to); + assert_eq!(names(h.state()), ["Second"]); + assert_eq!(h.state().ui.actions.selected, Some(0)); + assert_eq!(h.state().ui.actions.expanded.len(), 1); +} + +#[test] +fn action_dragged_onto_plus_adds_a_copy_after_it() { + let mut h = harness(); + let (from, to) = (center(&h, "First"), center(&h, "Create new action")); + drag(&mut h, from, to); + assert_eq!(names(h.state()).len(), 3); + assert_eq!(names(h.state())[0], "First"); + assert_eq!(names(h.state())[2], "Second"); + assert_eq!(steps(h.state(), 1), steps(h.state(), 0)); + assert!(h.state().session.actions.recording.is_none()); +} + +#[test] +fn step_dragged_onto_plus_duplicates_the_step_in_place() { + let mut h = harness(); + let (from, to) = (center(&h, "Fit on Screen"), center(&h, "Create new action")); + drag(&mut h, from, to); + assert_eq!(names(h.state()), ["First", "Second"]); + assert_eq!(steps(h.state(), 0), ["view.zoomOut", "view.fitOnScreen", "view.fitOnScreen", "view.actualPixels"]); +} + +#[test] +fn drag_released_over_empty_space_changes_nothing() { + let mut h = harness(); + let from = center(&h, "Fit on Screen"); + drag(&mut h, from, pos2(160.0, 300.0)); + assert_eq!(names(h.state()), ["First", "Second"]); + assert_eq!(steps(h.state(), 0).len(), 3); + assert_eq!(steps(h.state(), 1).len(), 1); +} + +#[test] +fn action_dropped_on_trash_while_recording_is_not_deleted() { + let mut h = harness(); + h.state_mut().run("actions.record", json!({"name": "Rec"})).unwrap(); + h.run_steps(3); + let (from, to) = (center(&h, "Second"), center(&h, "Delete")); + drag(&mut h, from, to); + assert!(names(h.state()).contains(&"Second".to_string())); + assert!(names(h.state()).contains(&"First".to_string())); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index d605faf62a..f9f0a99f4d 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -274,6 +274,7 @@ Paragraph; the rest open as in-app floating windows. | Date | Change | Summary | |---|---|---| +| 2026-11-08 | minor | Actions panel: an action or step row dragged onto the trash is deleted, and one dragged onto Create new action is duplicated right after itself (#12373) | | 2026-11-08 | minor | Image › Adjustments › Photo Filter… keeps Preserve Luminosity from its last OK; filter, colour and density reopen at Warming Filter (85) and 25 %, measured in the reference application (#9879); no percentage changed | | 2026-11-07 | minor | Gradient stops dragged off the bar are removed, with a live preview and drag-back cancel, in every stop editor: Gradient Map and Layer Style gained it, the Gradient Editor, Properties and shape popover share the same threshold (#10742); row added (done); no percentage changed | | 2026-11-07 | minor | Foreground/background colours restored before the first frame (`Preferences.toolColors`, #8485), with separate pixel/mask pairs, HDR/alpha, exact CMYK ink picks and a final normal-exit flush; malformed values are ignored one by one, and first saves from older preferences merge against the default swatches so separate edits in two instances survive. No percentage changed | From c1a109f894e31d71c3293dbf3572a39445a02af4 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sun, 8 Nov 2026 15:06:50 -0500 Subject: [PATCH 2/3] Actions panel: the drop target is outlined only, so its icon stays visible (#12373) The hover highlight filled the footer button with the opaque hover colour over the icon. It is now a 1.5 px accent outline. control-protocol.md's Actions panel paragraph mentions the two drags. Co-Authored-By: Claude Opus 5.5 Model-Effort: Opus 5.5 drove and wrote --- crates/ui-egui/src/panels/actions.rs | 6 +++--- docs/control-protocol.md | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index 8c411f732f..5a6274a796 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -1774,11 +1774,11 @@ fn delete_row(app: &mut PhotocraftApp, action: usize, step: Option) -> bo true } -/// Outline a footer button a dragged row would be dropped on. +/// Outline a footer button a dragged row would be dropped on (an outline only, so the icon +/// stays visible). fn drop_target_highlight(ui: &egui::Ui, response: &egui::Response, active: bool, t: &Tokens) { if active && response.contains_pointer() { - ui.painter().rect_filled(response.rect, t.radius_sm, t.hover); - ui.painter().rect_stroke(response.rect, t.radius_sm, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside); + ui.painter().rect_stroke(response.rect, t.radius_sm, Stroke::new(1.5, t.accent), egui::StrokeKind::Inside); } } diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 7ebf31bbe9..230554b536 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -176,6 +176,7 @@ heading instead targets the whole action. Step deletion also works during record and does not undo the document edit. The control equivalent is `actions.delete {"action": "Name", "step": 0}` (zero-based). Omitting `step` deletes the whole action, which still requires recording to be stopped. +A step or action row dragged onto the trash is deleted without a confirmation, and one dragged onto the plus button is duplicated right after itself (`actions.duplicate`), as in Photoshop. Desktop actions also record and replay View › Fit on Screen (`view.fitOnScreen`), 100% (`view.actualPixels`), Zoom In and Zoom Out through their menu commands or shortcuts. From bdc8b6a7f2aba1c5728fb3222c2b9d3a548d8858 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sun, 8 Nov 2026 16:32:40 -0500 Subject: [PATCH 3/3] Actions panel: an open name field stays on its action when another is deleted or copied (#12373) delete_row and duplicate_row shifted the selection and the disclosure rows but not the action being renamed in place, so a field open on a later action could move to its neighbour. Deleting the renamed action now closes the field, deleting an earlier one moves it up, and a copy inserted at or before it moves it down. Co-Authored-By: Claude Opus 5.5 Model-Effort: Opus 5.5 drove and wrote --- crates/ui-egui/src/panels/actions.rs | 20 +++++++++-- .../src/panels/actions/drag_drop_tests.rs | 34 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/actions.rs b/crates/ui-egui/src/panels/actions.rs index 5a6274a796..3ecc6708b0 100644 --- a/crates/ui-egui/src/panels/actions.rs +++ b/crates/ui-egui/src/panels/actions.rs @@ -1720,6 +1720,10 @@ fn duplicate_row(app: &mut PhotocraftApp, action: usize, step: Option) -> if index <= app.ui.actions.expanded.len() { app.ui.actions.expanded.insert(index, expanded); } + // A name field open on an action at or after the copy moves down with that action. + if let Some(r) = app.ui.actions.renaming.as_mut().filter(|r| r.index >= index) { + r.index += 1; + } } else { app.ui.actions.expanded.resize(count, false); if let Some(expanded) = app.ui.actions.expanded.get_mut(index) { @@ -1768,8 +1772,20 @@ fn delete_row(app: &mut PhotocraftApp, action: usize, step: Option) -> bo }, _ => {} } - if step.is_none() && action < ui.expanded.len() { - ui.expanded.remove(action); + if step.is_none() { + if action < ui.expanded.len() { + ui.expanded.remove(action); + } + // A name field open on the deleted action closes; one on a later action moves up with it. + match ui.renaming.as_ref().map(|r| r.index) { + Some(i) if i == action => ui.renaming = None, + Some(i) if i > action => { + if let Some(r) = ui.renaming.as_mut() { + r.index = i - 1; + } + } + _ => {} + } } true } diff --git a/crates/ui-egui/src/panels/actions/drag_drop_tests.rs b/crates/ui-egui/src/panels/actions/drag_drop_tests.rs index 2b0268b9f9..2c89514886 100644 --- a/crates/ui-egui/src/panels/actions/drag_drop_tests.rs +++ b/crates/ui-egui/src/panels/actions/drag_drop_tests.rs @@ -103,3 +103,37 @@ fn action_dropped_on_trash_while_recording_is_not_deleted() { assert!(names(h.state()).contains(&"Second".to_string())); assert!(names(h.state()).contains(&"First".to_string())); } + +fn rename_open_on(app: &mut PhotocraftApp, index: usize, text: &str) { + app.ui.actions.renaming = Some(RenameAction { index, text: text.into(), focused: true }); +} + +fn renaming(app: &PhotocraftApp) -> Option<(usize, String)> { + app.ui.actions.renaming.as_ref().map(|r| (r.index, r.text.clone())) +} + +#[test] +fn an_open_name_field_stays_on_its_action_when_another_is_deleted_or_copied() { + let mut h = harness(); + let app = h.state_mut(); + // Deleting the action above moves the field up with its action. + rename_open_on(app, 1, "Second renamed"); + assert!(delete_row(app, 0, None)); + assert_eq!(renaming(app), Some((0, "Second renamed".into()))); + // Deleting the action being renamed closes the field. + assert!(delete_row(app, 0, None)); + assert_eq!(renaming(app), None); + + let mut h = harness(); + let app = h.state_mut(); + // A copy inserted above moves the field down with its action; one below leaves it. + rename_open_on(app, 1, "Second renamed"); + duplicate_row(app, 0, None).unwrap(); + assert_eq!(renaming(app), Some((2, "Second renamed".into()))); + duplicate_row(app, 2, None).unwrap(); + assert_eq!(renaming(app), Some((2, "Second renamed".into()))); + // Deleting or copying a step leaves it alone. + assert!(delete_row(app, 0, Some(0))); + duplicate_row(app, 0, Some(0)).unwrap(); + assert_eq!(renaming(app), Some((2, "Second renamed".into()))); +}