Skip to content

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

LRC-LIB-KEYWORDS: Esc in Add keyword gives back the text from before

Nathaniel Ledfordfe02cfe2e132
diff --git a/crates/ui-egui/src/panels/right.rs b/crates/ui-egui/src/panels/right.rs
index f9a2ce9e5..3afbdf1bb 100644
--- a/crates/ui-egui/src/panels/right.rs
+++ b/crates/ui-egui/src/panels/right.rs
@@ -778,10 +778,8 @@ fn keywords(app: &mut LightcraftApp, ui: &mut egui::Ui, id: PhotoId) {
let mut text = ui.data_mut(|d| d.get_temp::<String>(kid).unwrap_or_default());
let r =
crate::text_field::TextField::singleline("field:keyword", &mut text).hint(crate::i18n::tr("Add keyword")).width(f32::INFINITY).show(ui);
- // Return gives the keywords to the selected photos; Esc gives up what was typed
- if r.cancelled() {
- text.clear();
- }
+ // Return gives the keywords to the selected photos; Esc gives back what was there before
+ // this edit (the shared field does)
if r.ending == Some(crate::text_field::Ending::Return) && !text.trim().is_empty() {
// a new name goes inside the default parent (Put New Keywords Inside This Keyword)
let kws: Vec<String> = text.split(',').map(|s| app.session.catalog.typed_keyword(s)).filter(|s| !s.is_empty()).collect();
diff --git a/crates/ui-egui/src/tests_keywording.rs b/crates/ui-egui/src/tests_keywording.rs
index ffc37bb0e..93352650a 100644
--- a/crates/ui-egui/src/tests_keywording.rs
+++ b/crates/ui-egui/src/tests_keywording.rs
@@ -195,3 +195,21 @@ fn the_active_photo_alone_is_the_selection() {
assert_eq!(ticks.tick("Weddings"), crate::panels::keyword_list::Tick::All);
assert!(has(&h, "keywordCheck:beach"));
}
+
+/// Esc in the Add keyword box gives back what it held before this edit, as every text field does:
+/// text left there by an earlier edit stays.
+#[test]
+fn escape_gives_back_the_text_from_before_the_edit() {
+ let (mut h, ids) = two_selected();
+ ask(&mut h, "ui.clickWidget", json!({"id": "field:keyword"}));
+ ask(&mut h, "ui.text", json!({"text": "harbour"}));
+ ask(&mut h, "ui.key", json!({"key": "Tab"}));
+ ask(&mut h, "ui.clickWidget", json!({"id": "field:keyword"}));
+ ask(&mut h, "ui.key", json!({"key": "End"}));
+ ask(&mut h, "ui.text", json!({"text": ", sea"}));
+ ask(&mut h, "ui.key", json!({"key": "Escape"}));
+ ask(&mut h, "ui.clickWidget", json!({"id": "field:keyword"}));
+ ask(&mut h, "ui.key", json!({"key": "Enter"}));
+ let k = keywords_of(&h, ids[0]);
+ assert!(k.contains(&"harbour".to_string()) && !k.contains(&"sea".to_string()), "{k:?}");
+}