Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Smart Filters: Delete/Backspace removes the selected filter, not its smart object (#4751)

Marco Arnulfo14b1783e9345
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 522c74dc1..ebc6b24fb 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -2409,6 +2409,8 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
{
actions.push(done);
}
+ // Likewise a selected smart filter whose row is gone.
+ crate::smart_ui::forget_hidden(ui.ctx(), doc.id);
});
// A layer being dragged can also be dropped on the footer's Delete, New Layer and Group
// buttons (#736); read the drag before it ends.
diff --git a/crates/ui-egui/src/shortcut_dispatch.rs b/crates/ui-egui/src/shortcut_dispatch.rs
index 4336315db..e89db8b2e 100644
--- a/crates/ui-egui/src/shortcut_dispatch.rs
+++ b/crates/ui-egui/src/shortcut_dispatch.rs
@@ -272,7 +272,7 @@ pub fn dispatch_pressed(app: &mut PhotocraftApp, ctx: &egui::Context, focus: Foc
/// selection is filled with the background colour in the mask (Photoshop's Delete on a mask), and
/// with no selection the mask itself is deleted, as Layer › Layer Mask › Delete, unless several
/// layers are selected: then they are deleted.
-fn delete_key_command(app: &PhotocraftApp, id: String) -> String {
+pub(crate) fn delete_key_command(app: &PhotocraftApp, id: String) -> String {
if id != "edit.clear" {
return id;
}
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index e8645a151..8d597f510 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -517,6 +517,10 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
if crate::guide_select::keys(app, ctx) {
return;
}
+ // A selected smart filter row: ⌫/Delete removes the filter, not its smart object (#4751).
+ if crate::smart_ui::keys(app, ctx) {
+ return;
+ }
// Space+F (⇧Space+F backwards) cycles the pasteboard colour, as in Photoshop: F while the
// Hand key is held, before F's own Cycle Screen Mode.
if !matches!(focus, Focus::Text) && app.ui.text_edit.is_none() && crate::hold_keys::reposition_held(app, ctx) {
diff --git a/crates/ui-egui/src/smart_filter_rows_tests.rs b/crates/ui-egui/src/smart_filter_rows_tests.rs
index 9db54bbe1..d05e02e01 100644
--- a/crates/ui-egui/src/smart_filter_rows_tests.rs
+++ b/crates/ui-egui/src/smart_filter_rows_tests.rs
@@ -229,3 +229,91 @@ fn clicking_the_smart_object_row_deselects_its_filter() {
click_at(&mut h, trash);
assert_eq!(filters(&h, a).len(), 2, "the filters stay");
}
+
+/// #4751: Delete or Backspace removes the selected filter, as the Delete button does, not the
+/// smart object; on the Smart Filters row it clears them all.
+#[test]
+fn the_delete_key_removes_the_selected_filter() {
+ let (mut h, a, _, _) = panel();
+ let blur = at(&h, "Gaussian Blur");
+ click_at(&mut h, blur);
+ h.key_press(egui::Key::Delete);
+ h.run_steps(4);
+ assert_eq!(filters(&h, a), ["filter.other.offset"]);
+ assert_eq!(h.state().session.active().unwrap().doc.layers.len(), 4, "no layer was deleted");
+ let row = at(&h, "Smart Filters");
+ click_at(&mut h, row);
+ h.key_press(egui::Key::Backspace);
+ h.run_steps(4);
+ assert!(filters(&h, a).is_empty());
+ assert_eq!(h.state().session.active().unwrap().doc.layers.len(), 4, "no layer was deleted");
+}
+
+/// A text field keeps its Delete: renaming the smart object leaves the selected filter alone.
+#[test]
+fn the_delete_key_in_a_text_field_leaves_the_filter() {
+ let (mut h, a, _, _) = panel();
+ let blur = at(&h, "Gaussian Blur");
+ click_at(&mut h, blur);
+ let ctx = h.ctx.clone();
+ crate::layer_row_ui::start_rename(&ctx, a, "Smart A");
+ h.run_steps(4);
+ assert!(selected(&h, "Gaussian Blur"), "the filter is still selected while renaming");
+ h.key_press(egui::Key::Delete);
+ h.run_steps(4);
+ assert_eq!(filters(&h, a).len(), 2);
+ assert_eq!(h.state().session.active().unwrap().doc.layers.len(), 4);
+}
+
+/// Quick Mask keeps Delete for Edit › Clear on the mask, even with a filter's row selected.
+#[test]
+fn the_delete_key_in_quick_mask_clears_the_mask_not_the_filter() {
+ let (mut h, a, _, _) = panel();
+ let blur = at(&h, "Gaussian Blur");
+ click_at(&mut h, blur);
+ // No selection: Quick Mask alone must keep the key, not a marquee's Edit › Clear.
+ h.state_mut().run("select.editInQuickMaskMode", json!({"on": true})).unwrap();
+ assert!(h.state().session.active().unwrap().doc.selection.is_none());
+ h.run_steps(4);
+ assert!(selected(&h, "Gaussian Blur"), "the filter is still selected in Quick Mask");
+ h.key_press(egui::Key::Delete);
+ h.run_steps(4);
+ assert_eq!(filters(&h, a).len(), 2);
+ assert_eq!(h.state().session.active().unwrap().doc.layers.len(), 4);
+}
+
+/// A filter whose row isn't drawn (here the panel is filtered by name) is no longer selected:
+/// Delete then deletes the active layer as usual, never a filter nobody sees highlighted.
+#[test]
+fn a_hidden_filter_row_is_deselected() {
+ let (mut h, a, _, _) = panel();
+ let blur = at(&h, "Gaussian Blur");
+ click_at(&mut h, blur);
+ h.state_mut().ui.layer_filter_by = crate::layer_filter_ui::FilterBy::Name;
+ h.state_mut().ui.layer_filter_name = "Pixels".into();
+ h.run_steps(4);
+ // Shown again, the row is no longer highlighted: the selection went, it wasn't just hidden.
+ h.state_mut().ui.layer_filter_name.clear();
+ h.run_steps(4);
+ assert!(!selected(&h, "Gaussian Blur"));
+ h.key_press(egui::Key::Delete);
+ h.run_steps(4);
+ let st = h.state().session.active().unwrap();
+ assert!(st.doc.layer(LayerId(a)).is_none(), "Delete reached Smart A itself");
+}
+
+/// With the Layers panel closed the selected row isn't on screen either, so Delete deletes the
+/// active layer as usual.
+#[test]
+fn with_the_layers_panel_closed_delete_leaves_the_filter() {
+ let (mut h, a, _, _) = panel();
+ let blur = at(&h, "Gaussian Blur");
+ click_at(&mut h, blur);
+ let ctx = h.ctx.clone();
+ crate::menus::invoke(h.state_mut(), &ctx, "window.toggle.layers", json!({})).unwrap();
+ h.run_steps(4);
+ assert!(h.query_all_by_label("Gaussian Blur").next().is_none(), "the panel is closed");
+ h.key_press(egui::Key::Delete);
+ h.run_steps(4);
+ assert!(h.state().session.active().unwrap().doc.layer(LayerId(a)).is_none(), "Delete reached Smart A itself");
+}
diff --git a/crates/ui-egui/src/smart_ui.rs b/crates/ui-egui/src/smart_ui.rs
index 7f49843c5..48fc7dd12 100644
--- a/crates/ui-egui/src/smart_ui.rs
+++ b/crates/ui-egui/src/smart_ui.rs
@@ -145,6 +145,12 @@ pub fn filter_rows(app: &mut PhotocraftApp, ui: &mut egui::Ui, l: &Layer, depth:
open_editor(app, ui.ctx(), l.id.0, sm, i);
}
}
+ // Every row of `l` is drawn, so a filter of it selected (now, after this pass's clicks) is on
+ // screen: see [`forget_hidden`].
+ if ui.ctx().data(|d| d.get_temp::<FilterDrag>(selected_key(doc))).is_some_and(|(layer, _)| layer == l.id.0) {
+ let pass = ui.ctx().cumulative_pass_nr();
+ ui.ctx().data_mut(|d| d.insert_temp(drawn_key(doc), pass));
+ }
}
/// Smart filter rows being dragged: the smart object and the filter index (`None` = the Smart
@@ -160,12 +166,22 @@ fn selected_key(doc: photocraft_doc::DocId) -> egui::Id {
egui::Id::new(("smart-filter-selected", doc))
}
-/// The selected smart filter row, while its smart object is active and the filter still exists.
+/// The pass in which the selected smart filter row of a document was last drawn.
+fn drawn_key(doc: photocraft_doc::DocId) -> egui::Id {
+ egui::Id::new(("smart-filter-selected-drawn", doc))
+}
+
+/// The selected smart filter row, while its smart object is active, the filter still exists and
+/// its row is on screen (drawn this pass or the last: the Layers panel may be closed).
pub(crate) fn selected(ctx: &egui::Context, doc: &Document, active: Option<LayerId>) -> Option<FilterDrag> {
let (layer, filter) = ctx.data(|d| d.get_temp::<FilterDrag>(selected_key(doc.id)))?;
if active != Some(LayerId(layer)) {
return None;
}
+ let drawn = ctx.data(|d| d.get_temp::<u64>(drawn_key(doc.id)))?;
+ if drawn + 1 < ctx.cumulative_pass_nr() {
+ return None;
+ }
let LayerContent::Smart(sm) = &doc.layer(LayerId(layer))?.content else { return None };
let exists = match filter {
Some(i) => i < sm.smart_filters.len(),
@@ -180,6 +196,17 @@ pub(crate) fn deselect(ctx: &egui::Context, doc: photocraft_doc::DocId) {
ctx.data_mut(|d| d.remove::<FilterDrag>(selected_key(doc)));
}
+/// Forgets the selected smart filter row when the Layers panel didn't draw it this pass (its smart
+/// object is in a closed group, filtered out or isolated away): Delete must never remove a filter
+/// nobody sees highlighted.
+pub(crate) fn forget_hidden(ctx: &egui::Context, doc: photocraft_doc::DocId) {
+ let picked = ctx.data(|d| d.get_temp::<FilterDrag>(selected_key(doc)));
+ let drawn = ctx.data(|d| d.get_temp::<u64>(drawn_key(doc)));
+ if picked.is_some() && drawn != Some(ctx.cumulative_pass_nr()) {
+ deselect(ctx, doc);
+ }
+}
+
/// While smart filters are dragged: their name by the pointer, and the copy cursor while ⌥ is held.
pub(crate) fn drag_feedback(ctx: &egui::Context, doc: &Document) {
let Some((from, filter)) = ctx.data(|d| d.get_temp::<FilterDrag>(drag_key())) else { return };
@@ -275,6 +302,36 @@ pub(crate) fn trash_action((layer, filter): FilterDrag) -> (String, Value) {
}
}
+/// Delete or Backspace with no modifiers while a filter's row is selected removes that filter (the
+/// Smart Filters row: all of them), as the panel's Delete button does (#4751), instead of
+/// deleting the smart object or reaching Edit › Clear.
+pub(crate) fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
+ use crate::shortcut_dispatch::Focus;
+ // Text fields and widgets that delete with these keys themselves keep them (#1534).
+ if app.ui.text_edit.is_some() || matches!(Focus::of(ctx), Focus::Text | Focus::DeletingWidget) {
+ return false;
+ }
+ let Some(st) = app.session.active() else { return false };
+ let Some(picked) = selected(ctx, &st.doc, st.active_layer) else { return false };
+ let doc = st.doc.id;
+ // Only where the key would delete the smart object: Quick Mask, a single channel, a targeted
+ // mask or a selection keep their own Delete.
+ if crate::shortcut_dispatch::delete_key_command(app, "edit.clear".into()) != "layer.delete" {
+ return false;
+ }
+ let mods = ctx.input(|i| i.modifiers);
+ if !mods.is_none() || !ctx.input_mut(|i| i.consume_key(mods, egui::Key::Delete) || i.consume_key(mods, egui::Key::Backspace)) {
+ return false;
+ }
+ let (command, params) = trash_action(picked);
+ deselect(ctx, doc);
+ if let Err(e) = app.run(&command, params) {
+ app.ui.status = e;
+ app.ui.status_error = true;
+ }
+ true
+}
+
/// Re-opens a smart filter's dialog with its recorded parameters; OK runs
/// `layer.smartFilter.setParams` instead of adding another filter (see `dialogs::confirm`).
pub fn open_editor(app: &mut PhotocraftApp, ctx: &egui::Context, layer: u64, sm: &SmartObject, index: usize) {
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 793f09840..9de205e7b 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-15 · **Change:** minor (Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-15 · **Change:** minor (⌫/Delete removes the selected smart filter, #4751; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -219,7 +219,7 @@ Paragraph; the rest open as in-app floating windows.
| Document tabs: overflow, context menu, reorder | done | UI-217-6; middle-click close #2570 |
| Layers panel: wheel steps blend modes, drop on New/Trash | partial | UI-217-14 |
| Layers panel filter-type dropdown (Kind, Name, Effect, Mode, Attribute, Color, Smart Object, Selected, Artboard) | partial | Kind, Name and Mode; the other six missing. `layer_filter_ui.rs`, `ui.set {layerFilter}` (#5048) |
-| Smart filter rows: click selects, drag onto another smart object moves, ⌥-drag copies, drag onto Delete removes | done | `smart_ui.rs`, `layer.smartFilter.transfer` (#4271) |
+| Smart filter rows: click selects, drag onto another smart object moves, ⌥-drag copies, drag onto Delete removes; with a row selected, the Delete button and the ⌫/Delete key remove that filter, not the smart object | done | `smart_ui.rs`, `layer.smartFilter.transfer` (#4271), `smart_ui::keys` (#4751) |
| Layers panel: Clip Thumbnails to Layer Bounds (panel menu, `interface.clipThumbnailsToLayerBounds`) | done (2026-10-12) | `layer_thumb_bounds_tests.rs`; #4281. Thumbnail size and the Panel Options dialog to come |
| Smart filter rows: drag up or down the stack to reorder (a line marks the drop; the bottom filter is applied first) | done | `smart_ui.rs` `reorder_drop`, `layer.smartFilter.move` |
@@ -257,3 +257,4 @@ Paragraph; the rest open as in-app floating windows.
| 2026-10-14 | minor | Last selected tool restored across launches; temporary overrides excluded, explicit Eraser choices retained, and final selection flushed on normal exit |
| 2026-10-13 | minor | Free Transform with a selection: the box is the selection's rectangle, and the marching ants follow it while it is transformed (#5297) |
| 2026-10-14 | minor | Move › Show Transform Controls frames every selected layer and outlines the selected shapes |
+| 2026-10-15 | minor | ⌫/Delete with a smart filter row selected removes that filter (the Smart Filters row: all of them), as the Delete button does, instead of the smart object (#4751) |