diff --git a/crates/ui-egui/src/tools/analysis_ui.rs b/crates/ui-egui/src/tools/analysis_ui.rs index 8d45b7c89b..a60b60e832 100644 --- a/crates/ui-egui/src/tools/analysis_ui.rs +++ b/crates/ui-egui/src/tools/analysis_ui.rs @@ -1085,14 +1085,16 @@ pub fn clear_notes_body(ui: &mut egui::Ui) { ui.label(tl!("Are you sure you want to delete all notes?")); } -/// OK: every note goes in one step and nothing stays selected, so the options bar shows the -/// tool's values again. +/// OK: every note goes in one step, nothing stays selected, and the options bar shows the tool +/// defaults again (a selected note had put its author and colour there). pub fn confirm_clear_notes(app: &mut PhotocraftApp, fields: &Map) -> Result { if app.session.active().map(|s| s.doc.id.0) != fields.get("document").and_then(Value::as_u64) { return Err(tl!("The document changed. Please choose Clear All again.").into()); } let result = app.run("notes.delete", json!({"all": true}))?; - app.ui.analysis.note_selected = None; + let defaults = AnalysisUi::default(); + let a = &mut app.ui.analysis; + (a.note_selected, a.note_author, a.note_color) = (None, defaults.note_author, defaults.note_color); Ok(result) } /// Its "Don't show again", kept with the other dialog preferences. diff --git a/crates/ui-egui/src/tools/note_clear_all_tests.rs b/crates/ui-egui/src/tools/note_clear_all_tests.rs index a30a253d85..5232d84d41 100644 --- a/crates/ui-egui/src/tools/note_clear_all_tests.rs +++ b/crates/ui-egui/src/tools/note_clear_all_tests.rs @@ -187,3 +187,17 @@ fn enter_is_ok_and_escape_is_cancel() { assert_eq!(steps(h.state()), before + usize::from(left == 0), "{key:?}: history"); } } + +#[test] +fn ok_brings_back_the_tool_defaults_in_the_options_bar() { + let mut app = app(); + app.run("notes.set", json!({"index": 1, "color": "#3366cc"})).unwrap(); + // Clicking the note shows its author and colour in the options bar (#7940). + show_note_options(&mut app, 1); + assert_eq!(app.ui.analysis.note_author, "B"); + let mut h = harness(app); + let id = clear_all(&mut h); + crate::dialogs::confirm(h.state_mut(), id).unwrap(); + let (defaults, a) = (AnalysisUi::default(), &h.state().ui.analysis); + assert_eq!((a.note_author.as_str(), a.note_color), (defaults.note_author.as_str(), defaults.note_color), "the tool defaults after OK"); +}