Skip to content

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

Issue #2980: Clear Color Label's toast ignores a label parameter

x-labbedcc801a9cf4
diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs
index 0b2685e59..b7f45fe15 100644
--- a/crates/ui-egui/src/app.rs
+++ b/crates/ui-egui/src/app.rs
@@ -252,7 +252,8 @@ impl LightcraftApp {
}
}
if r.is_ok() && matches!(id, "photo.label" | "photo.clearLabel") {
- let label = params.get("label").and_then(Value::as_str).and_then(lightcraft_catalog::ColorLabel::parse);
+ // Clear Color Label takes no colour: whatever `label` it is given, the photo's label is cleared
+ let label = params.get("label").and_then(Value::as_str).and_then(lightcraft_catalog::ColorLabel::parse).filter(|_| id == "photo.label");
let text = match label {
Some(label) => {
let name =
diff --git a/crates/ui-egui/src/shortcuts/tests_clear_label.rs b/crates/ui-egui/src/shortcuts/tests_clear_label.rs
index 2c3db87a4..f1ea73eff 100644
--- a/crates/ui-egui/src/shortcuts/tests_clear_label.rs
+++ b/crates/ui-egui/src/shortcuts/tests_clear_label.rs
@@ -112,6 +112,15 @@ fn compare_clears_only_the_active_photo_and_auto_advance_moves_on() {
assert_eq!(app.session.active(), Some(PhotoId(2)));
}
+#[test]
+fn a_label_given_to_clear_color_label_is_ignored_by_the_toast_too() {
+ let mut app = app().unwrap();
+ app.run("photo.clearLabel", json!({"label": "red"})).unwrap();
+ assert_eq!(labels(&app)[1], None, "the photo's label is cleared, whatever label was passed");
+ let toast = app.ui.toast.as_ref().expect("a toast");
+ assert_eq!((toast.0.as_str(), toast.2), ("Color label cleared", None), "not \"Red Label\"");
+}
+
fn find<'a>(nodes: &'a [MenuNode], id: &str) -> Option<&'a MenuNode> {
nodes.iter().find_map(|n| match n {
MenuNode::Item { id: i, .. } if i == id => Some(n),