Skip to content

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

fix(ui): Delete with Slice Select deletes the selected slice, not the layer (#7862)

Korg1ch2c030a300c4a
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index 1ad8d6d92..d16caa9e2 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -555,6 +555,10 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
if crate::guide_select::keys(app, ctx) {
return;
}
+ // A slice selected with Slice Select: ⌫/Delete deletes the slice, not the layer (#7862).
+ if crate::slice_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/slice_ui.rs b/crates/ui-egui/src/slice_ui.rs
index 1e75bbd71..0ffc0f59c 100644
--- a/crates/ui-egui/src/slice_ui.rs
+++ b/crates/ui-egui/src/slice_ui.rs
@@ -206,6 +206,39 @@ fn selected_id(app: &mut PhotocraftApp, promote: bool) -> Option<u32> {
}
}
+/// Delete or Backspace with no modifiers, with the Slice Select tool and a slice selected,
+/// deletes that slice, as in Photoshop (#7862). It never reaches Layer › Delete or Edit › Clear.
+/// An auto slice has nothing to delete, and View › Lock Slices refuses with a message.
+pub 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.
+ if app.ui.tool != Tool::SliceSelect
+ || app.ui.slices.selected.is_none()
+ || app.ui.text_edit.is_some()
+ || matches!(Focus::of(ctx), Focus::Text | Focus::DeletingWidget)
+ {
+ 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 result = if app.session.file_menu.slices_locked {
+ Err(tl!("Slices are locked (View › Lock Slices)").to_string())
+ } else {
+ match selected_id(app, false) {
+ Some(id) => app.run("slice.delete", json!({"slice": id})).map(|_| app.ui.slices.selected = None),
+ // An auto slice is made from the user slices around it: it goes when they do.
+ None => Ok(()),
+ }
+ };
+ if let Err(e) = result {
+ app.ui.status = e;
+ app.ui.status_error = true;
+ }
+ true
+}
+
/// Slice Options dialog for the selected slice (auto slices are promoted on OK).
pub fn open_options(app: &mut PhotocraftApp) -> Result<Value, String> {
let n = app.ui.slices.selected.ok_or("select a slice with the Slice Select tool")?;