From 7159ab4265c9a42a1049d0e5430fceab291de96d Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 7 Nov 2026 15:57:10 -0600 Subject: [PATCH 1/6] Note tool: Clear All asks before deleting all notes; the step is named Delete all Notes (#11791) --- crates/engine/src/cmd/notes_cmds.rs | 3 +- crates/ui-egui/src/dialogs.rs | 11 +- crates/ui-egui/src/tools/analysis_ui.rs | 45 ++++++- .../ui-egui/src/tools/note_clear_all_tests.rs | 123 ++++++++++++++++++ 4 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 crates/ui-egui/src/tools/note_clear_all_tests.rs diff --git a/crates/engine/src/cmd/notes_cmds.rs b/crates/engine/src/cmd/notes_cmds.rs index 2f589f3390..2c3cf2f64c 100644 --- a/crates/engine/src/cmd/notes_cmds.rs +++ b/crates/engine/src/cmd/notes_cmds.rs @@ -131,7 +131,8 @@ fn set(s: &mut Session, p: &Value) -> Result { fn delete(s: &mut Session, p: &Value) -> Result { if p.get("all").and_then(Value::as_bool) == Some(true) { let n = s.active().map_or(0, |d| d.doc.notes.len()); - s.edit("Delete All Notes", |d, _| { + // Photoshop's name for the step, with a lower-case "all" (#11791). + s.edit("Delete all Notes", |d, _| { d.notes.clear(); Ok(()) })?; diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 82a1b6a093..bc6da0423e 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -277,13 +277,16 @@ pub(crate) fn close_box(ui: &mut egui::Ui, rect: egui::Rect) -> bool { /// it. Returns `Some(true)` / `Some(false)` when the body itself answered OK / Cancel. /// The body of a command dialog: the first handler whose marker the fields carry. The prompts and /// small editors come first; the rest are in `command_body_more`. -/// The delete confirmations: a layer from the Layers panel's trash, or a note (#11788). +/// The delete confirmations: a layer from the Layers panel's trash, a note (#11788), or all notes +/// (#11791). fn delete_prompt(fields: &Fields) -> bool { - crate::delete_layer_prompt::owns(fields) || crate::analysis_ui::owns_delete_note(fields) + crate::delete_layer_prompt::owns(fields) || crate::analysis_ui::owns_delete_note(fields) || crate::analysis_ui::owns_clear_notes(fields) } fn delete_prompt_body(ui: &mut egui::Ui, fields: &mut Fields) { - if crate::analysis_ui::owns_delete_note(fields) { + if crate::analysis_ui::owns_clear_notes(fields) { + crate::analysis_ui::clear_notes_body(ui); + } else if crate::analysis_ui::owns_delete_note(fields) { crate::analysis_ui::delete_note_body(ui, fields); } else { crate::delete_layer_prompt::body(ui, fields); @@ -883,6 +886,7 @@ const ROUTES: &[fn(&Fields) -> bool] = &[ crate::shape_dialog::owns, crate::delete_layer_prompt::owns, crate::analysis_ui::owns_delete_note, + crate::analysis_ui::owns_clear_notes, crate::disk_change_prompt::owns, crate::actions::owns_stop_message, crate::actions::owns_insert_stop, @@ -1104,6 +1108,7 @@ fn confirm_command_more(app: &mut PhotocraftApp, d: Dialog) -> Result merge_channels_ui::confirm(app, &d.fields), _ if crate::analysis_ui::owns_delete_note(&d.fields) => crate::analysis_ui::confirm_delete_note(app, &d.fields), + _ if crate::analysis_ui::owns_clear_notes(&d.fields) => crate::analysis_ui::confirm_clear_notes(app, &d.fields), _ if crate::file_ui::owns(&d.fields) => crate::file_ui::confirm(app, &d.fields), _ if crate::new_guide_ui::owns(&d.fields) => crate::new_guide_ui::confirm(app, &d.fields), _ if crate::color_picker_ui::owns(&d.fields) => { diff --git a/crates/ui-egui/src/tools/analysis_ui.rs b/crates/ui-egui/src/tools/analysis_ui.rs index ed113909a6..857ac97a5a 100644 --- a/crates/ui-egui/src/tools/analysis_ui.rs +++ b/crates/ui-egui/src/tools/analysis_ui.rs @@ -593,9 +593,9 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo if crate::widgets::color_swatch_button(ui, color32(rgb), tl!("Color")).clicked() { crate::color_picker_ui::open_for_target(app, "noteColor", &crate::color_picker_ui::title_for(tl!("Color")), rgb); } + // Clear All asks first (#11791); `notes.delete {"all": true}` itself never does. if ui.add_enabled_ui(!doc.notes.is_empty(), |ui| crate::widgets::secondary_button(ui, tl!("Clear All"), 0.0)).inner.clicked() { - let _ = app.run("notes.delete", json!({"all": true})); - app.ui.analysis.note_selected = None; + ask_clear_notes(app); } if crate::icons::button(ui, "message-square", 22.0, app.ui.analysis.notes, tl!("Show or hide the Notes panel")).clicked() { app.ui.analysis.notes = !app.ui.analysis.notes; @@ -1000,6 +1000,43 @@ pub(crate) mod tests; /// Marks the "Delete this note?" alert (#11788). const DELETE_NOTE_MARK: &str = "__deleteNote"; + +/// Marks the "Are you sure you want to delete all notes?" alert (#11791). +const CLEAR_NOTES_MARK: &str = "__clearAllNotes"; + +/// The Note tool's Clear All: Photoshop's alert, OK / Cancel (#11791). OK deletes every note in one +/// "Delete all Notes" step; Cancel (or Escape) changes nothing. +pub fn ask_clear_notes(app: &mut PhotocraftApp) { + let Some(doc) = app.session.active().filter(|s| !s.doc.notes.is_empty()).map(|s| s.doc.id.0) else { return }; + if app.ui.dialogs.iter().any(|d| owns_clear_notes(&d.fields)) { + return; + } + let mut f = Map::new(); + f.insert(CLEAR_NOTES_MARK.into(), json!(true)); + f.insert("__command".into(), json!("notes.delete")); + f.insert("__label".into(), json!(tl!("Clear All"))); + f.insert("document".into(), json!(doc)); + app.ui.open_dialog(crate::state::DialogKind::Command, f); +} + +pub fn owns_clear_notes(fields: &Map) -> bool { + fields.contains_key(CLEAR_NOTES_MARK) +} + +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. +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; + Ok(result) +} /// Its "Don't show again", kept with the other dialog preferences. const DELETE_NOTE_PREF: &str = "notes.delete.confirmation"; @@ -1091,3 +1128,7 @@ pub fn note_keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool { #[cfg(test)] #[path = "note_delete_key_tests.rs"] mod note_delete_key_tests; + +#[cfg(test)] +#[path = "note_clear_all_tests.rs"] +mod note_clear_all_tests; diff --git a/crates/ui-egui/src/tools/note_clear_all_tests.rs b/crates/ui-egui/src/tools/note_clear_all_tests.rs new file mode 100644 index 0000000000..15a2f8932a --- /dev/null +++ b/crates/ui-egui/src/tools/note_clear_all_tests.rs @@ -0,0 +1,123 @@ +//! #11791: the Note tool's Clear All asks "Are you sure you want to delete all notes?" first. OK +//! deletes every note in one "Delete all Notes" step that one undo restores; Cancel changes +//! nothing; `notes.delete {"all": true}` itself never asks. + +use egui::vec2; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::json; + +use super::*; + +/// A 200 × 100 document with three notes, the second one selected, and the Note tool. +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + for (x, author) in [(10, "A"), (60, "B"), (110, "C")] { + app.run("notes.add", json!({"x": x, "y": 20, "author": author})).unwrap(); + } + app.ui.tool = Tool::Note; + app.ui.analysis.note_selected = Some(1); + app +} + +fn harness(app: PhotocraftApp) -> Harness<'static, PhotocraftApp> { + let mut h = Harness::builder().with_size(vec2(1200.0, 80.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + crate::panels::options_bar(app, ui); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Studio); + h.run_steps(4); + h +} + +fn notes(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().doc.notes.len() +} + +fn steps(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().history.past_len() +} + +/// The open Clear All alert's id. +fn alert(app: &PhotocraftApp) -> Option { + app.ui.dialogs.iter().find(|d| owns_clear_notes(&d.fields)).map(|d| d.id) +} + +/// Click the options bar's Clear All and return the alert it opened. +fn clear_all(h: &mut Harness<'static, PhotocraftApp>) -> u64 { + h.get_by_label("Clear All").click(); + h.run_steps(3); + alert(h.state()).expect("Clear All opens the alert") +} + +#[test] +fn clear_all_asks_first_and_cancel_changes_nothing() { + let mut h = harness(app()); + let before = steps(h.state()); + let id = clear_all(&mut h); + assert_eq!(notes(h.state()), 3, "nothing is deleted before the answer"); + let ctx = egui::Context::default(); + let mut texts = Vec::new(); + let mut o = ctx.run_ui(egui::RawInput::default(), clear_notes_body); + o.textures_delta.clear(); + for c in o.shapes { + if let egui::Shape::Text(t) = c.shape { + texts.push(t.galley.text().to_owned()); + } + } + assert!(texts.iter().any(|t| t == "Are you sure you want to delete all notes?"), "{texts:?}"); + crate::dialogs::cancel(h.state_mut(), id).unwrap(); + assert_eq!(notes(h.state()), 3); + assert_eq!(steps(h.state()), before, "no history step"); + assert_eq!(h.state().ui.analysis.note_selected, Some(1), "the selection stays"); +} + +#[test] +fn ok_deletes_every_note_in_one_step_that_undo_restores() { + let mut h = harness(app()); + let before = steps(h.state()); + let id = clear_all(&mut h); + crate::dialogs::confirm(h.state_mut(), id).unwrap(); + h.run_steps(3); + let app = h.state(); + assert_eq!(notes(app), 0); + assert_eq!(steps(app), before + 1, "one history step"); + assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Delete all Notes")); + assert_eq!(app.ui.analysis.note_selected, None, "nothing selected after OK"); + assert!(h.get_by_label("Clear All").accesskit_node().is_disabled(), "Clear All greys without notes"); + h.state_mut().run("edit.undo", json!({})).unwrap(); + assert_eq!(notes(h.state()), 3, "one undo brings every note back"); +} + +#[test] +fn the_command_itself_never_asks_and_names_its_step_too() { + let mut app = app(); + app.run("notes.delete", json!({"all": true})).unwrap(); + assert_eq!(notes(&app), 0); + assert!(alert(&app).is_none(), "no alert from the command"); + assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Delete all Notes")); +} + +#[test] +fn clear_all_stays_grey_without_notes() { + let mut app = app(); + app.run("notes.delete", json!({"all": true})).unwrap(); + ask_clear_notes(&mut app); + assert!(alert(&app).is_none(), "nothing to ask about"); + let h = harness(app); + assert!(h.get_by_label("Clear All").accesskit_node().is_disabled()); +} + +#[test] +fn a_second_click_while_the_alert_is_open_opens_no_second_alert() { + let mut h = harness(app()); + clear_all(&mut h); + ask_clear_notes(h.state_mut()); + assert_eq!(h.state().ui.dialogs.iter().filter(|d| owns_clear_notes(&d.fields)).count(), 1); +} From dd3588cd4efa8e73eb660555e14f747f3c7f41c9 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 7 Nov 2026 18:42:30 -0600 Subject: [PATCH 2/6] Note Clear All tests: OK after the document changed deletes nothing (eliets2 review on crates/ui-egui/src/tools/note_clear_all_tests.rs, confirm_clear_notes) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/note_clear_all_tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 15a2f8932a..4e5c9a4784 100644 --- a/crates/ui-egui/src/tools/note_clear_all_tests.rs +++ b/crates/ui-egui/src/tools/note_clear_all_tests.rs @@ -121,3 +121,17 @@ fn a_second_click_while_the_alert_is_open_opens_no_second_alert() { ask_clear_notes(h.state_mut()); assert_eq!(h.state().ui.dialogs.iter().filter(|d| owns_clear_notes(&d.fields)).count(), 1); } + +#[test] +fn ok_after_the_document_changed_deletes_nothing() { + let mut h = harness(app()); + let id = clear_all(&mut h); + let app = h.state_mut(); + app.run("file.new", json!({"width": 50, "height": 50})).unwrap(); + app.run("notes.add", json!({"x": 5, "y": 5})).unwrap(); + let past: Vec = app.session.documents().iter().map(|d| d.history.past_len()).collect(); + assert!(crate::dialogs::confirm(app, id).is_err(), "the alert was for the first document"); + let docs = app.session.documents(); + assert_eq!(docs.iter().map(|d| d.doc.notes.len()).collect::>(), [3, 1], "no note deleted in either document"); + assert_eq!(docs.iter().map(|d| d.history.past_len()).collect::>(), past, "no history step in either"); +} From 45bb76a7ab5b9d66169aa0781d3dcd4d59d05665 Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 7 Nov 2026 18:42:36 -0600 Subject: [PATCH 3/6] Note Clear All tests: the second Clear All is a real click (eliets2 review on crates/ui-egui/src/tools/note_clear_all_tests.rs, second-click test) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/note_clear_all_tests.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 4e5c9a4784..c585887fe7 100644 --- a/crates/ui-egui/src/tools/note_clear_all_tests.rs +++ b/crates/ui-egui/src/tools/note_clear_all_tests.rs @@ -118,7 +118,9 @@ fn clear_all_stays_grey_without_notes() { fn a_second_click_while_the_alert_is_open_opens_no_second_alert() { let mut h = harness(app()); clear_all(&mut h); - ask_clear_notes(h.state_mut()); + // The options bar alone, so nothing covers Clear All: the second click reaches the button. + h.get_by_label("Clear All").click(); + h.run_steps(3); assert_eq!(h.state().ui.dialogs.iter().filter(|d| owns_clear_notes(&d.fields)).count(), 1); } From 0ac80298ba198dba8c40f99e4191c3b83cf80ebc Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 7 Nov 2026 18:42:43 -0600 Subject: [PATCH 4/6] Note Clear All tests: the alert drawn through dialogs.rs, its question and its OK / Cancel clicked (eliets2 review on crates/ui-egui/src/tools/note_clear_all_tests.rs, dialog rendering) Co-Authored-By: Claude Opus 5.5 --- .../ui-egui/src/tools/note_clear_all_tests.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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 c585887fe7..39a2cc4f10 100644 --- a/crates/ui-egui/src/tools/note_clear_all_tests.rs +++ b/crates/ui-egui/src/tools/note_clear_all_tests.rs @@ -137,3 +137,39 @@ fn ok_after_the_document_changed_deletes_nothing() { assert_eq!(docs.iter().map(|d| d.doc.notes.len()).collect::>(), [3, 1], "no note deleted in either document"); assert_eq!(docs.iter().map(|d| d.history.past_len()).collect::>(), past, "no history step in either"); } + +/// The options bar with the open dialogs drawn over it, as the window shows them. +fn harness_with_dialogs(app: PhotocraftApp) -> Harness<'static, PhotocraftApp> { + let mut h = Harness::builder().with_size(vec2(1200.0, 600.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if !ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + crate::panels::options_bar(app, ui); + crate::dialogs::show(app, ui.ctx()); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Studio); + h.run_steps(4); + h +} + +#[test] +fn the_alert_shows_its_question_and_its_buttons_answer() { + for (button, left) in [("Cancel", 3), ("OK", 0)] { + let mut h = harness_with_dialogs(app()); + let before = steps(h.state()); + let id = clear_all(&mut h); + let d = h.state().ui.dialogs.iter().find(|d| d.id == id).unwrap(); + assert_eq!(crate::dialogs::title(d), "Clear All"); + let question = egui_kittest::kittest::by().label("Are you sure you want to delete all notes?").include_labels(); + assert!(h.query_all(question).next().is_some(), "the question is shown"); + assert!(h.query_by_label("OK").is_some() && h.query_by_label("Cancel").is_some(), "OK and Cancel"); + h.get_by_label(button).click(); + h.run_steps(3); + assert!(alert(h.state()).is_none(), "{button} closes the alert"); + assert_eq!(notes(h.state()), left, "{button}: {left} notes left"); + assert_eq!(steps(h.state()), before + usize::from(left == 0), "{button}: history"); + } +} From 5d601bbd984c00341373e1456872051c612a033f Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sat, 7 Nov 2026 18:42:50 -0600 Subject: [PATCH 5/6] Note Clear All tests: Enter is OK and Escape is Cancel (eliets2 review on crates/ui-egui/src/tools/note_clear_all_tests.rs, keyboard) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/tools/note_clear_all_tests.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 39a2cc4f10..a30a253d85 100644 --- a/crates/ui-egui/src/tools/note_clear_all_tests.rs +++ b/crates/ui-egui/src/tools/note_clear_all_tests.rs @@ -173,3 +173,17 @@ fn the_alert_shows_its_question_and_its_buttons_answer() { assert_eq!(steps(h.state()), before + usize::from(left == 0), "{button}: history"); } } + +#[test] +fn enter_is_ok_and_escape_is_cancel() { + for (key, left) in [(egui::Key::Escape, 3), (egui::Key::Enter, 0)] { + let mut h = harness_with_dialogs(app()); + let before = steps(h.state()); + clear_all(&mut h); + h.key_press(key); + h.run_steps(3); + assert!(alert(h.state()).is_none(), "{key:?} closes the alert"); + assert_eq!(notes(h.state()), left, "{key:?}: {left} notes left"); + assert_eq!(steps(h.state()), before + usize::from(left == 0), "{key:?}: history"); + } +} From c3bd5e2fa3822ea140c3964abbe3ce7cb1d70a3c Mon Sep 17 00:00:00 2001 From: Hector Villarreal Date: Sun, 8 Nov 2026 13:48:51 -0600 Subject: [PATCH 6/6] 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) --- crates/ui-egui/src/tools/analysis_ui.rs | 8 +++++--- crates/ui-egui/src/tools/note_clear_all_tests.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) 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"); +}