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

The box emptied itself on Esc, on top of the shared field's own undo of
the edit: text left there by an earlier edit (ended by clicking away)
went too. Esc now gives back what the box held before the edit, as
every text field does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nathaniel Ledford 2026-10-09 15:40:33 -04:00
parent c2bc46d747
commit fe02cfe2e1
No known key found for this signature in database
2 changed files with 20 additions and 4 deletions

View File

@ -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();

View File

@ -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:?}");
}