Clear All's OK brings back the Note tool's default author and colour (CodeRabbit review on crates/ui-egui/src/tools/analysis_ui.rs:1096)

This commit is contained in:
Hector Villarreal committed 2026-11-08 13:48:51 -06:00
1 parent 091f8a2666
commit c3bd5e2fa3
2 files changed
+19 -3

No files matched your search

+5 -3
View File
@@ -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<String, Value>) -> Result<Value, String> {
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.
@@ -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");
}