From 44f02f663f14dcbb228a65809078f53a69521d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 19:42:34 -0500 Subject: [PATCH 1/8] fix(ui): switching map says when it drops an unsaved Format text or cancels a service import (#2987) --- crates/ui-egui/src/graphicformat.rs | 60 +++++++++++++++++++++++++++-- crates/ui-egui/src/serviceui.rs | 56 ++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index 3ca4aacc14..a388c85415 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -141,7 +141,7 @@ pub fn show(app: &mut RustGisApp, ui: &mut egui::Ui, t: &Tokens) { } let _ = app.run("graphics.edit", p); }; - if settled.typing { + if settled.typing && text != current { app.graphic_format.draft = Some((k, opened, text)); } else if settled.text && text != current { save(app, json!({"text": text})); @@ -169,8 +169,8 @@ pub fn show(app: &mut RustGisApp, ui: &mut egui::Ui, t: &Tokens) { /// Saves the text typed for a graphic the pane didn't draw this frame (the pane was closed or /// hidden, or the selection changed) before its field could say it lost focus. A draft for -/// another project, or another map than the one shown, is dropped: its layer ids and rows aren't -/// this one's. Runs once a frame, after the panes and the view. +/// another project, or another map than the one shown, is dropped, and that is said (#2987): its +/// layer ids and rows aren't this one's. Runs once a frame, after the panes and the view. pub(crate) fn save_draft(app: &mut RustGisApp) { let drawn = app.graphic_format.drawn.take(); let Some((k, opened, text)) = app.graphic_format.draft.take() else { return }; @@ -180,9 +180,14 @@ pub(crate) fn save_draft(app: &mut RustGisApp) { } let (map, layer, row) = k; let here = opened == app.session.opened && map == app.session.map().instance_id(); + // What was typed for a map no longer in view can't be saved there, and the typing isn't lost without a word. + if !here { + app.session.notify(tl!("Text typed for a graphic on another map or project was not saved.").to_string(), false); + return; + } let current = app.session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string); // A blank text goes to `graphics.edit` too, which refuses it and says so, as when Enter ends it. - if here && current.is_some_and(|c| c != text) { + if current.is_some_and(|c| c != text) { let _ = app.run("graphics.edit", json!({"layer": layer, "row": row, "text": text})); } } @@ -286,6 +291,7 @@ mod tests { h.run_steps(2); h.query_all_by_role(Role::MultilineTextInput).find(|n| n.is_focused()).unwrap().type_text("New"); h.run_steps(2); + let mark = h.state().session.notice_mark(); h.state_mut().run("map.new", json!({"name": "Second"})).unwrap(); h.state_mut().run("map.activate", json!({"name": first})).unwrap(); h.state_mut().run("map.move", json!({"name": first, "to": 1})).unwrap(); @@ -296,6 +302,52 @@ mod tests { h.run_steps(2); let label = h.state().session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string); assert!(label.as_deref().is_some_and(|t| t.contains("New")), "{label:?}"); + assert!(h.state().session.notices_since(mark).iter().all(|n| !n.text.contains("was not saved")), "moved, not dropped"); + } + + /// A text typed for a map that is then replaced in view is not saved, and that is said once (#2987); + /// one moved with its map is kept without a word (`moving_the_map_keeps_the_text_being_typed`). + #[test] + fn a_text_typed_for_a_map_no_longer_in_view_says_it_was_not_saved() { + let mut app = RustGisApp::with_sample(); + let added = app.run("graphics.add", json!({"shape": "text", "points": [[10, 50]], "text": "Old"})).unwrap(); + let (layer, row) = (added["layer"].as_u64().unwrap() as u32, added["row"].as_u64().unwrap() as usize); + let mut h = harness(app); + h.run_steps(2); + h.state_mut().run("select.rows", json!({"layer": layer, "rows": [row]})).unwrap(); + h.run_steps(3); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.value().as_deref() == Some("Old")).unwrap().focus(); + h.run_steps(2); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.is_focused()).unwrap().type_text("New"); + h.run_steps(2); + let mark = h.state().session.notice_mark(); + h.state_mut().run("map.new", json!({"name": "Second"})).unwrap(); + h.run_steps(3); + let said = |h: &egui_kittest::Harness<'_, RustGisApp>| { + h.state().session.notices_since(mark).iter().filter(|n| n.text.contains("was not saved")).count() + }; + assert_eq!(said(&h), 1, "{:?}", h.state().session.notices_since(mark).iter().map(|n| &n.text).collect::>()); + h.run_steps(3); + assert_eq!(said(&h), 1, "once, not every frame"); + assert!(h.state().graphic_format.draft.is_none()); + } + + /// A text field focused but not edited has nothing pending: switching map says nothing of it (#2987). + #[test] + fn a_focused_text_nobody_edited_leaves_no_notice_when_the_map_changes() { + let mut app = RustGisApp::with_sample(); + let added = app.run("graphics.add", json!({"shape": "text", "points": [[10, 50]], "text": "Old"})).unwrap(); + let (layer, row) = (added["layer"].as_u64().unwrap() as u32, added["row"].as_u64().unwrap() as usize); + let mut h = harness(app); + h.run_steps(2); + h.state_mut().run("select.rows", json!({"layer": layer, "rows": [row]})).unwrap(); + h.run_steps(3); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.value().as_deref() == Some("Old")).unwrap().focus(); + h.run_steps(2); + let mark = h.state().session.notice_mark(); + h.state_mut().run("map.new", json!({"name": "Second"})).unwrap(); + h.run_steps(3); + assert!(h.state().session.notices_since(mark).iter().all(|n| !n.text.contains("was not saved"))); } /// A text cleared in the pane is refused, as `graphics.edit` refuses one: when Enter ends it and diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index 0ddb8132ca..1f4056e92d 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -466,10 +466,15 @@ impl Import { pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { let Some(mut task) = app.ui.service_import.take() else { return }; - if !app.session.download_is_pending(task.token) || crate::dialogs::map_key(&app.session) != task.map { + if !app.session.download_is_pending(task.token) { app.session.download_failed(task.token); return; } + if crate::dialogs::map_key(&app.session) != task.map { + app.session.download_failed(task.token); + app.session.notify(tl!("The service import was cancelled because the map in view changed or was renamed.").to_string(), false); + return; + } let landed = task.slot.lock().unwrap_or_else(|e| e.into_inner()).take(); if let Some(answer) = landed && let Err(e) = answer.and_then(|bytes| task.landed(app, bytes)) @@ -682,6 +687,55 @@ fn noted(app: &mut RustGisApp, landed: &Landed, note: Option) { mod tests { use super::*; + /// An import in flight that is given up because the map in view changed says so, once; one whose + /// download is already over says nothing (#2987). + #[test] + fn an_import_given_up_for_another_map_says_so() { + let mut app = RustGisApp::with_sample(); + let first = app.session.map().name.clone(); + let task = |app: &mut RustGisApp| Import { + params: json!({}), + refresh: false, + connection: None, + token: app.session.download_started(), + map: crate::dialogs::map_key(&app.session), + slot: Slot::default(), + document: Some("https://example.test/capabilities".into()), + current: None, + remaining: VecDeque::new(), + responses: Vec::new(), + bytes: 0, + }; + let ctx = egui::Context::default(); + let said = |app: &RustGisApp, mark: u64| { + app.session.notices_since(mark).iter().filter(|n| n.text.contains("service import was cancelled")).count() + }; + // Another map in view: said once. + let mark = app.session.notice_mark(); + let import = task(&mut app); + app.ui.service_import = Some(import); + app.run("map.new", json!({"name": "Second"})).unwrap(); + poll(&mut app, &ctx); + assert_eq!(said(&app, mark), 1); + assert!(app.ui.service_import.is_none()); + // Its map renamed: the name is part of what it finds its map by. + app.run("map.activate", json!({"name": first})).unwrap(); + let mark = app.session.notice_mark(); + let import = task(&mut app); + app.ui.service_import = Some(import); + app.run("map.rename", json!({"name": "Renamed"})).unwrap(); + poll(&mut app, &ctx); + assert_eq!(said(&app, mark), 1); + // A download already over (cancelled by the user, say): nothing more to say. + let mark = app.session.notice_mark(); + let import = task(&mut app); + app.session.download_failed(import.token); + app.ui.service_import = Some(import); + app.run("map.activate", json!({"name": "Second"})).unwrap(); + poll(&mut app, &ctx); + assert_eq!(said(&app, mark), 0); + } + /// An import in flight goes on when its map moves among the maps, and is given up when another /// map is in view (#2959). #[test] From 89bb2f2ce2e63f464cc4cad0a35122eab4a83a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 20:35:26 -0500 Subject: [PATCH 2/8] fix(ui): an import also says it was cancelled when another project is opened (#2987) --- crates/ui-egui/src/dialogs.rs | 5 +++++ crates/ui-egui/src/serviceui.rs | 37 +++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 846174a3d1..a026f41973 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -35,6 +35,11 @@ impl MapOwner { Self { project: s.opened, map: map_key(s) } } + /// Whether `s` still has the project open it was made in. + pub(crate) fn in_project(&self, s: &Session) -> bool { + self.project == s.opened + } + /// Whether `s` still has that project open with that map in view (a moved map is the same one). pub(crate) fn holds(&self, s: &Session) -> bool { let map = s.map(); diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index 1f4056e92d..461352a2b0 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -74,9 +74,9 @@ pub struct Import { /// The saved web-service connection to record on imported layers, not a group-plan parameter. connection: Option, token: u64, - /// The originating map (`dialogs::map_key`), so a deleted, replaced or renamed map cancels the - /// import and a moved one doesn't. - map: crate::dialogs::MapKey, + /// The project and map it started on (`dialogs::MapOwner`), so another project, or a deleted, + /// replaced or renamed map, cancels the import and a moved one doesn't. + owner: crate::dialogs::MapOwner, slot: Slot, String>>, document: Option, current: Option, @@ -342,7 +342,7 @@ pub fn start(app: &mut RustGisApp, p: &Value, refresh: bool) -> Result<(), Strin refresh, connection, token: app.session.download_started(), - map: crate::dialogs::map_key(&app.session), + owner: crate::dialogs::MapOwner::of(&app.session), slot: Slot::default(), document: None, current: None, @@ -466,13 +466,15 @@ impl Import { pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { let Some(mut task) = app.ui.service_import.take() else { return }; - if !app.session.download_is_pending(task.token) { + let pending = app.session.download_is_pending(task.token); + let moved = !task.owner.holds(&app.session); + if !pending || moved { app.session.download_failed(task.token); - return; - } - if crate::dialogs::map_key(&app.session) != task.map { - app.session.download_failed(task.token); - app.session.notify(tl!("The service import was cancelled because the map in view changed or was renamed.").to_string(), false); + // Said unless the download was already over for the user's own reason (Cancel): opening + // another project puts its downloads aside, so they are never pending here. + if moved && (pending || !task.owner.in_project(&app.session)) { + app.session.notify(tl!("The service import was cancelled because the map or project in view changed.").to_string(), false); + } return; } let landed = task.slot.lock().unwrap_or_else(|e| e.into_inner()).take(); @@ -698,7 +700,7 @@ mod tests { refresh: false, connection: None, token: app.session.download_started(), - map: crate::dialogs::map_key(&app.session), + owner: crate::dialogs::MapOwner::of(&app.session), slot: Slot::default(), document: Some("https://example.test/capabilities".into()), current: None, @@ -734,6 +736,15 @@ mod tests { app.run("map.activate", json!({"name": "Second"})).unwrap(); poll(&mut app, &ctx); assert_eq!(said(&app, mark), 0); + // Another project opened: its download is put aside with the project, so it is no longer + // pending here, and that is said all the same. + app.run("map.activate", json!({"name": "Second"})).unwrap(); + let mark = app.session.notice_mark(); + let import = task(&mut app); + app.ui.service_import = Some(import); + app.run("project.new", json!({})).unwrap(); + poll(&mut app, &ctx); + assert_eq!(said(&app, mark), 1); } /// An import in flight goes on when its map moves among the maps, and is given up when another @@ -748,7 +759,7 @@ mod tests { refresh: false, connection: None, token, - map: crate::dialogs::map_key(&app.session), + owner: crate::dialogs::MapOwner::of(&app.session), slot: Slot::default(), document: Some("https://example.test/capabilities".into()), current: None, @@ -1071,7 +1082,7 @@ mod tests { refresh: false, connection: None, token: 0, - map: (0, String::new()), + owner: crate::dialogs::MapOwner::of(&rustgis_engine::Session::new(rustgis_engine::Project::default())), slot: Slot::default(), document: None, current: None, From 2772ffd18e9b400c9b2ffa5a8d3aa97f3cebb7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 20:49:57 -0500 Subject: [PATCH 3/8] fix(ui): a typed text whose graphic is gone says it was not saved (#2987) --- crates/ui-egui/src/graphicformat.rs | 34 +++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index a388c85415..7ae453f579 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -169,8 +169,9 @@ pub fn show(app: &mut RustGisApp, ui: &mut egui::Ui, t: &Tokens) { /// Saves the text typed for a graphic the pane didn't draw this frame (the pane was closed or /// hidden, or the selection changed) before its field could say it lost focus. A draft for -/// another project, or another map than the one shown, is dropped, and that is said (#2987): its -/// layer ids and rows aren't this one's. Runs once a frame, after the panes and the view. +/// another project, or another map than the one shown, is dropped, and so is one whose graphic is +/// gone, and that is said (#2987): the layer ids and rows of another map aren't this one's. Runs once +/// a frame, after the panes and the view. pub(crate) fn save_draft(app: &mut RustGisApp) { let drawn = app.graphic_format.drawn.take(); let Some((k, opened, text)) = app.graphic_format.draft.take() else { return }; @@ -185,9 +186,13 @@ pub(crate) fn save_draft(app: &mut RustGisApp) { app.session.notify(tl!("Text typed for a graphic on another map or project was not saved.").to_string(), false); return; } - let current = app.session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string); + let Some(current) = app.session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string) else { + // Its layer was removed, or its row is no longer a text. + app.session.notify(tl!("Text typed for a graphic that is no longer there was not saved.").to_string(), false); + return; + }; // A blank text goes to `graphics.edit` too, which refuses it and says so, as when Enter ends it. - if current.is_some_and(|c| c != text) { + if current != text { let _ = app.run("graphics.edit", json!({"layer": layer, "row": row, "text": text})); } } @@ -332,6 +337,27 @@ mod tests { assert!(h.state().graphic_format.draft.is_none()); } + /// A text typed for a graphic that is then gone (its layer removed) is not saved, and that is said once. + #[test] + fn a_text_typed_for_a_graphic_that_is_gone_says_it_was_not_saved() { + let mut app = RustGisApp::with_sample(); + let added = app.run("graphics.add", json!({"shape": "text", "points": [[10, 50]], "text": "Old"})).unwrap(); + let (layer, row) = (added["layer"].as_u64().unwrap() as u32, added["row"].as_u64().unwrap() as usize); + let mut h = harness(app); + h.run_steps(2); + h.state_mut().run("select.rows", json!({"layer": layer, "rows": [row]})).unwrap(); + h.run_steps(3); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.value().as_deref() == Some("Old")).unwrap().focus(); + h.run_steps(2); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.is_focused()).unwrap().type_text("New"); + h.run_steps(2); + let mark = h.state().session.notice_mark(); + h.state_mut().run("layer.remove", json!({"layer": layer})).unwrap(); + h.run_steps(3); + let said = h.state().session.notices_since(mark).iter().filter(|n| n.text.contains("was not saved")).count(); + assert_eq!(said, 1, "{:?}", h.state().session.notices_since(mark).iter().map(|n| &n.text).collect::>()); + } + /// A text field focused but not edited has nothing pending: switching map says nothing of it (#2987). #[test] fn a_focused_text_nobody_edited_leaves_no_notice_when_the_map_changes() { From 0f92457ffa24c10395177956affa0466ce20e1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 21:10:18 -0500 Subject: [PATCH 4/8] docs(ui): the import's silent case says what it covers, and the gone-graphic test checks the draft is cleared (#2987) --- crates/ui-egui/src/graphicformat.rs | 1 + crates/ui-egui/src/serviceui.rs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index 7ae453f579..ae2bff662f 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -356,6 +356,7 @@ mod tests { h.run_steps(3); let said = h.state().session.notices_since(mark).iter().filter(|n| n.text.contains("was not saved")).count(); assert_eq!(said, 1, "{:?}", h.state().session.notices_since(mark).iter().map(|n| &n.text).collect::>()); + assert!(h.state().graphic_format.draft.is_none()); } /// A text field focused but not edited has nothing pending: switching map says nothing of it (#2987). diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index 461352a2b0..3fd3519303 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -470,8 +470,8 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { let moved = !task.owner.holds(&app.session); if !pending || moved { app.session.download_failed(task.token); - // Said unless the download was already over for the user's own reason (Cancel): opening - // another project puts its downloads aside, so they are never pending here. + // Said unless the download was already over before the map moved (it failed elsewhere, + // say): opening another project puts its downloads aside, so they are never pending here. if moved && (pending || !task.owner.in_project(&app.session)) { app.session.notify(tl!("The service import was cancelled because the map or project in view changed.").to_string(), false); } @@ -728,7 +728,7 @@ mod tests { app.run("map.rename", json!({"name": "Renamed"})).unwrap(); poll(&mut app, &ctx); assert_eq!(said(&app, mark), 1); - // A download already over (cancelled by the user, say): nothing more to say. + // A download already over (failed elsewhere, say): nothing more to say. let mark = app.session.notice_mark(); let import = task(&mut app); app.session.download_failed(import.token); From 2679b11ca6f8e5254d8cc687d7d91db31ea2bbd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 21:21:53 -0500 Subject: [PATCH 5/8] docs(ui): clearer comments on the dropped-draft and import notices, and holds reuses in_project (#2987) --- crates/ui-egui/src/dialogs.rs | 2 +- crates/ui-egui/src/graphicformat.rs | 2 +- crates/ui-egui/src/serviceui.rs | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index a026f41973..9d0f895cb4 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -43,7 +43,7 @@ impl MapOwner { /// Whether `s` still has that project open with that map in view (a moved map is the same one). pub(crate) fn holds(&self, s: &Session) -> bool { let map = s.map(); - self.project == s.opened && self.map.0 == map.instance_id() && self.map.1 == map.name + self.in_project(s) && self.map.0 == map.instance_id() && self.map.1 == map.name } } diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index ae2bff662f..623e006431 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -181,7 +181,7 @@ pub(crate) fn save_draft(app: &mut RustGisApp) { } let (map, layer, row) = k; let here = opened == app.session.opened && map == app.session.map().instance_id(); - // What was typed for a map no longer in view can't be saved there, and the typing isn't lost without a word. + // Typing for a map no longer in view can't be saved there: it is dropped, and said. if !here { app.session.notify(tl!("Text typed for a graphic on another map or project was not saved.").to_string(), false); return; diff --git a/crates/ui-egui/src/serviceui.rs b/crates/ui-egui/src/serviceui.rs index 3fd3519303..b9c10780f8 100644 --- a/crates/ui-egui/src/serviceui.rs +++ b/crates/ui-egui/src/serviceui.rs @@ -471,7 +471,8 @@ pub fn poll(app: &mut RustGisApp, ctx: &egui::Context) { if !pending || moved { app.session.download_failed(task.token); // Said unless the download was already over before the map moved (it failed elsewhere, - // say): opening another project puts its downloads aside, so they are never pending here. + // say). Opening another project drops or puts aside its downloads, so they are never + // pending here. if moved && (pending || !task.owner.in_project(&app.session)) { app.session.notify(tl!("The service import was cancelled because the map or project in view changed.").to_string(), false); } From 5b3ad5fbd6bd2e751631ae391b195d35376319e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 21:31:13 -0500 Subject: [PATCH 6/8] fix(ui): a text graphic with empty text is not reported gone when its typed text is saved (#2987) --- crates/ui-egui/src/graphicformat.rs | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index 623e006431..9d96a78ec7 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -186,8 +186,14 @@ pub(crate) fn save_draft(app: &mut RustGisApp) { app.session.notify(tl!("Text typed for a graphic on another map or project was not saved.").to_string(), false); return; } - let Some(current) = app.session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string) else { - // Its layer was removed, or its row is no longer a text. + let Some(current) = app + .session + .map() + .layer(layer) + .filter(|l| graphics::kind(&l.dataset, row) == "text") + .map(|l| graphics::label(&l.dataset, row).unwrap_or_default().to_string()) + else { + // Its layer was removed, or its row is no longer a text (a text whose text is empty still is one). app.session.notify(tl!("Text typed for a graphic that is no longer there was not saved.").to_string(), false); return; }; @@ -359,6 +365,29 @@ mod tests { assert!(h.state().graphic_format.draft.is_none()); } + /// A text graphic whose text is empty (`graphics.style` accepts one) still exists: what is typed for + /// it is saved when the pane closes, not reported as gone. + #[test] + fn a_text_typed_for_a_graphic_with_empty_text_is_saved_not_reported_gone() { + let mut app = RustGisApp::with_sample(); + let added = app.run("graphics.add", json!({"shape": "text", "points": [[10, 50]], "text": "Old"})).unwrap(); + let (layer, row) = (added["layer"].as_u64().unwrap() as u32, added["row"].as_u64().unwrap() as usize); + app.run("select.rows", json!({"layer": layer, "rows": [row]})).unwrap(); + app.run("graphics.style", json!({"text": ""})).unwrap(); + let mut h = harness(app); + h.run_steps(3); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.value().as_deref() == Some("")).unwrap().focus(); + h.run_steps(2); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.is_focused()).unwrap().type_text("New"); + h.run_steps(2); + let mark = h.state().session.notice_mark(); + h.state_mut().run("ui.pane.format", json!({})).unwrap(); + h.run_steps(2); + let label = h.state().session.map().layer(layer).and_then(|l| graphics::label(&l.dataset, row)).map(str::to_string); + assert!(label.as_deref().is_some_and(|t| t.contains("New")), "{label:?}"); + assert!(h.state().session.notices_since(mark).iter().all(|n| !n.text.contains("no longer there"))); + } + /// A text field focused but not edited has nothing pending: switching map says nothing of it (#2987). #[test] fn a_focused_text_nobody_edited_leaves_no_notice_when_the_map_changes() { From b82ffc375f7b17a9139ec1dae7d431d36578daac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 22:00:14 -0500 Subject: [PATCH 7/8] test(ui): a text too long for a graphic says why it was not saved when the pane closes (#2987) --- crates/ui-egui/src/graphicformat.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index 9d96a78ec7..3562e4f918 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -388,6 +388,28 @@ mod tests { assert!(h.state().session.notices_since(mark).iter().all(|n| !n.text.contains("no longer there"))); } + /// A text too long for a graphic (`graphics.edit` takes at most 2000 characters) is refused when the + /// pane closes over it, and that is said, not dropped in silence. + #[test] + fn a_text_too_long_to_save_says_why_when_the_pane_closes() { + let mut app = RustGisApp::with_sample(); + let added = app.run("graphics.add", json!({"shape": "text", "points": [[10, 50]], "text": "Old"})).unwrap(); + let (layer, row) = (added["layer"].as_u64().unwrap() as u32, added["row"].as_u64().unwrap() as usize); + let mut h = harness(app); + h.run_steps(2); + h.state_mut().run("select.rows", json!({"layer": layer, "rows": [row]})).unwrap(); + h.run_steps(3); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.value().as_deref() == Some("Old")).unwrap().focus(); + h.run_steps(2); + h.query_all_by_role(Role::MultilineTextInput).find(|n| n.is_focused()).unwrap().type_text(&"x".repeat(2001)); + h.run_steps(2); + let mark = h.state().session.notice_mark(); + h.state_mut().run("ui.pane.format", json!({})).unwrap(); + h.run_steps(2); + let said: Vec = h.state().session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!(said.iter().any(|t| t.contains("2000")), "{said:?}"); + } + /// A text field focused but not edited has nothing pending: switching map says nothing of it (#2987). #[test] fn a_focused_text_nobody_edited_leaves_no_notice_when_the_map_changes() { From ccaa6bd20175996c78d84afaacc64c6b82c5a7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Wed, 25 Nov 2026 22:26:31 -0500 Subject: [PATCH 8/8] test(ui): the over-limit test pins the refusal's own wording (#2987) --- crates/ui-egui/src/graphicformat.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/graphicformat.rs b/crates/ui-egui/src/graphicformat.rs index 3562e4f918..9c73c441b0 100644 --- a/crates/ui-egui/src/graphicformat.rs +++ b/crates/ui-egui/src/graphicformat.rs @@ -407,7 +407,7 @@ mod tests { h.state_mut().run("ui.pane.format", json!({})).unwrap(); h.run_steps(2); let said: Vec = h.state().session.notices_since(mark).iter().map(|n| n.text.clone()).collect(); - assert!(said.iter().any(|t| t.contains("2000")), "{said:?}"); + assert!(said.iter().any(|t| t.contains("characters: a graphic's text takes at most 2000")), "{said:?}"); } /// A text field focused but not edited has nothing pending: switching map says nothing of it (#2987).