Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

M16.1: ⌫ deletes photos again (was bound to forward-delete), and never in the Masking/Remove/Red Eye panels

Brandon Thomas2c37c26d1ec0
diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rs
index 5030286e4..1f2bf12be 100644
--- a/crates/engine/src/cmd/library.rs
+++ b/crates/engine/src/cmd/library.rs
@@ -292,27 +292,19 @@ pub fn specs() -> Vec<CommandSpec> {
}
),
// ---- albums
- cmd!(
- "album.create",
- "New Album",
- ["File"],
- Some("Cmd+Shift+N"),
- "{name, parent?: folderId, folder?: bool, addSelected?: bool}",
- always,
- |s, p| {
- let name = str_param(p, "name").unwrap_or("Untitled Album").trim().to_string();
- if name.is_empty() {
- return Err(bad("album.create", "empty name"));
- }
- let folder = bool_or(p, "folder", false);
- let parent = p.get("parent").and_then(Value::as_u64).map(AlbumId);
- let photos = if !folder && bool_or(p, "addSelected", false) { s.targets(&Value::Null) } else { vec![] };
- let id = s.catalog.alloc_album_id();
- let cover = photos.first().copied();
- s.commit(if folder { "New Folder" } else { "New Album" }, Op::AddAlbum { album: Album { id, name, parent, folder, photos, cover } })?;
- Ok(json!({"id": id.0}))
+ cmd!("album.create", "New Album", ["File"], None, "{name, parent?: folderId, folder?: bool, addSelected?: bool}", always, |s, p| {
+ let name = str_param(p, "name").unwrap_or("Untitled Album").trim().to_string();
+ if name.is_empty() {
+ return Err(bad("album.create", "empty name"));
}
- ),
+ let folder = bool_or(p, "folder", false);
+ let parent = p.get("parent").and_then(Value::as_u64).map(AlbumId);
+ let photos = if !folder && bool_or(p, "addSelected", false) { s.targets(&Value::Null) } else { vec![] };
+ let id = s.catalog.alloc_album_id();
+ let cover = photos.first().copied();
+ s.commit(if folder { "New Folder" } else { "New Album" }, Op::AddAlbum { album: Album { id, name, parent, folder, photos, cover } })?;
+ Ok(json!({"id": id.0}))
+ }),
cmd!("album.rename", "Rename Album", [], None, "{id, name}", always, |s, p| {
let id = album_param(p, "id", "album.rename")?;
let name = str_param(p, "name").ok_or_else(|| bad("album.rename", "missing name"))?.to_string();
diff --git a/crates/ui-egui/src/shortcuts.rs b/crates/ui-egui/src/shortcuts.rs
index 1690be121..fd0dd6490 100644
--- a/crates/ui-egui/src/shortcuts.rs
+++ b/crates/ui-egui/src/shortcuts.rs
@@ -26,13 +26,14 @@ pub fn parse(s: &str) -> Option<(Modifiers, Key)> {
"Shift" => m.shift = true,
"Alt" => m.alt = true,
"Ctrl" => m.ctrl = true,
+ // "Delete" means the key labelled ⌫ (egui's Backspace); forward-delete also matches, see `matches`.
+ "Delete" => key = Some(Key::Backspace),
k => {
key = Key::from_name(k).or(match k {
"Right" => Some(Key::ArrowRight),
"Left" => Some(Key::ArrowLeft),
"Up" => Some(Key::ArrowUp),
"Down" => Some(Key::ArrowDown),
- "Delete" => Some(Key::Backspace),
"\\" => Some(Key::Backslash),
"/" => Some(Key::Slash),
"=" => Some(Key::Equals),
@@ -50,7 +51,10 @@ pub fn parse(s: &str) -> Option<(Modifiers, Key)> {
fn matches(i: &egui::InputState, m: Modifiers, k: Key) -> bool {
i.events.iter().any(|e| match e {
egui::Event::Key { key, pressed: true, modifiers, .. } => {
- *key == k && modifiers.command == m.command && modifiers.shift == m.shift && modifiers.alt == m.alt
+ (*key == k || (k == Key::Backspace && *key == Key::Delete))
+ && modifiers.command == m.command
+ && modifiers.shift == m.shift
+ && modifiers.alt == m.alt
}
_ => false,
})
@@ -117,6 +121,21 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {
} else if let Some(l) = f.strip_prefix("label:") {
let _ = app.run("photo.label", json!({"label": l}));
} else {
+ // Delete acts on what's being edited: the active mask in the Masking panel; never the
+ // photo while retouching (spots are removed from their own panel).
+ if f == "photo.delete" {
+ use crate::state::RightPanel as R;
+ match app.ui.right {
+ R::Masking => {
+ if app.session.active_mask.is_some() {
+ let _ = app.run("mask.delete", json!({}));
+ }
+ continue;
+ }
+ R::Remove | R::RedEye => continue,
+ _ => {}
+ }
+ }
// X is both reject (library) and swap crop aspect (crop tool)
if f == "photo.reject" && app.ui.right == crate::state::RightPanel::Crop {
let _ = app.run("crop.rotateAspect", json!({}));
@@ -140,6 +159,12 @@ pub fn handle(app: &mut LightcraftApp, ctx: &egui::Context) {
#[cfg(test)]
mod tests {
+
+ #[test]
+ fn delete_means_the_backspace_key() {
+ assert_eq!(parse("Delete"), Some((Modifiers::NONE, Key::Backspace)));
+ assert_eq!(parse("Cmd+Delete"), Some((Modifiers::COMMAND, Key::Backspace)));
+ }
use super::*;
#[test]