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 <[email protected]>
Model-Effort: Opus 5.5 drove and briefed; Sonnet 5.5 wrote at medium
This commit is contained in:
Trevor BrownandClaude Sonnet 5.5 committed 2026-11-08 15:03:19 -05:00
1 parent a17acfa7a7
commit a45699a4fe
3 files changed
+177 -11

No files matched your search

+71 -11
View File
@@ -1703,7 +1703,12 @@ fn duplicate_selection(app: &mut PhotocraftApp) -> Result<Value, String> {
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<usize>) -> Result<Value, String> {
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<Value, String> {
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<usize>) -> 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::<DragRow>(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::<DragRow>()
&& 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::<DragRow>() {
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;
@@ -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<String> {
app.session.actions.list.iter().map(|a| a.name.clone()).collect()
}
fn steps(app: &PhotocraftApp, action: usize) -> Vec<String> {
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()));
}
+1
View File
@@ -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 |