Repository navigation
Keep rejected map graphic text editable in the Format pane #3545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,13 +14,22 @@ use crate::theme::Tokens; | |||||||||||||||
| /// id and row: layer ids and rows are a map's own. | ||||||||||||||||
| type Key = (u64, u32, usize); | ||||||||||||||||
|
|
||||||||||||||||
| /// A refused edit stays in its box while the same graphic still holds the text it was typed over. | ||||||||||||||||
| struct RefusedText { | ||||||||||||||||
| graphic: Key, | ||||||||||||||||
| opened: u64, | ||||||||||||||||
| original: String, | ||||||||||||||||
| text: String, | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[derive(Default)] | ||||||||||||||||
| pub struct GraphicFormat { | ||||||||||||||||
| /// The text the pane last opened for: a new one opens it again, so closing the pane keeps the | ||||||||||||||||
| /// selection without the pane coming back by itself. | ||||||||||||||||
| formatted: Option<Key>, | ||||||||||||||||
| /// The text being typed: its graphic, the project it is for (`Session::opened`), and the text. | ||||||||||||||||
| draft: Option<(Key, u64, String)>, | ||||||||||||||||
| refused: Option<RefusedText>, | ||||||||||||||||
| /// The graphic the pane drew the form of this frame: a draft for any other is saved at the | ||||||||||||||||
| /// end of the frame (`save_draft`). | ||||||||||||||||
| drawn: Option<Key>, | ||||||||||||||||
|
|
@@ -105,12 +114,13 @@ pub fn show(app: &mut RustGisApp, ui: &mut egui::Ui, t: &Tokens) { | |||||||||||||||
| let k = key(app, (layer, row)); | ||||||||||||||||
| let opened = app.session.opened; | ||||||||||||||||
| app.graphic_format.drawn = Some(k); | ||||||||||||||||
| let refused = app.graphic_format.refused.take().filter(|r| r.graphic == k && r.opened == opened && r.original == current); | ||||||||||||||||
| // A draft for another text is left for `save_draft`. | ||||||||||||||||
| let mut text = match app.graphic_format.draft.take() { | ||||||||||||||||
| Some((dk, p, t)) if dk == k && p == opened => t, | ||||||||||||||||
| other => { | ||||||||||||||||
| app.graphic_format.draft = other; | ||||||||||||||||
| current.clone() | ||||||||||||||||
| refused.as_ref().map_or(¤t, |r| &r.text).clone() | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
| let heading = crate::i18n::fmt("Map: {kind}", &[("kind", tl_raw!("Text"))]); | ||||||||||||||||
|
|
@@ -135,20 +145,24 @@ pub fn show(app: &mut RustGisApp, ui: &mut egui::Ui, t: &Tokens) { | |||||||||||||||
| named_fonts: false, | ||||||||||||||||
| select, | ||||||||||||||||
| }; | ||||||||||||||||
| let settled = | ||||||||||||||||
| let Some(settled) = | ||||||||||||||||
| crate::textform::section(ui, "Text", |ui| crate::textform::show(ui, ("graphic_format", k), &[graphics::TOKENS], Vec::new, fields)) | ||||||||||||||||
| .unwrap_or_default(); | ||||||||||||||||
| else { | ||||||||||||||||
| return; | ||||||||||||||||
| }; | ||||||||||||||||
|
Comment on lines
+150
to
+152
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the Text section is collapsed, Suggested fix: put the refused state back before returning.
Suggested change
Regression test to add next to Category: bug |
||||||||||||||||
| let save = |app: &mut RustGisApp, change: serde_json::Value| { | ||||||||||||||||
| let mut p = json!({"layer": layer, "row": row}); | ||||||||||||||||
| if let (Some(p), Some(c)) = (p.as_object_mut(), change.as_object()) { | ||||||||||||||||
| p.extend(c.clone()); | ||||||||||||||||
| } | ||||||||||||||||
| let _ = app.run("graphics.edit", p); | ||||||||||||||||
| }; | ||||||||||||||||
| if settled.typing && text != current { | ||||||||||||||||
| if refused.as_ref().is_some_and(|r| r.text == text) { | ||||||||||||||||
| app.graphic_format.refused = refused; | ||||||||||||||||
| } else if settled.typing && text != current { | ||||||||||||||||
| app.graphic_format.draft = Some((k, opened, text)); | ||||||||||||||||
| } else if settled.text && text != current { | ||||||||||||||||
| save(app, json!({"text": text})); | ||||||||||||||||
| } else if settled.text && text != current && app.run("graphics.edit", json!({"layer": layer, "row": row, "text": text})).is_err() { | ||||||||||||||||
| app.graphic_format.refused = Some(RefusedText { graphic: k, opened, original: current, text }); | ||||||||||||||||
| } | ||||||||||||||||
| if settled.size { | ||||||||||||||||
| save(app, json!({"fontSize": size})); | ||||||||||||||||
|
|
@@ -178,6 +192,9 @@ pub fn show(app: &mut RustGisApp, ui: &mut egui::Ui, t: &Tokens) { | |||||||||||||||
| /// a frame, after the panes and the view. | ||||||||||||||||
| pub(crate) fn save_draft(app: &mut RustGisApp) { | ||||||||||||||||
| let drawn = app.graphic_format.drawn.take(); | ||||||||||||||||
| if drawn.is_none() { | ||||||||||||||||
| app.graphic_format.refused = None; | ||||||||||||||||
| } | ||||||||||||||||
| let Some((k, opened, text)) = app.graphic_format.draft.take() else { return }; | ||||||||||||||||
| if Some(k) == drawn && opened == app.session.opened { | ||||||||||||||||
| app.graphic_format.draft = Some((k, opened, text)); | ||||||||||||||||
|
|
@@ -290,6 +307,33 @@ mod tests { | |||||||||||||||
| assert!(edit(h.state_mut(), layer, row + 99).is_err()); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn a_refused_graphic_text_stays_in_the_box_until_corrected() { | ||||||||||||||||
| let mut app = RustGisApp::with_sample(); | ||||||||||||||||
| place(&mut app, 10.0, 50.0, Some("Old")).unwrap(); | ||||||||||||||||
| let (layer, row) = selected(&app).unwrap(); | ||||||||||||||||
| let mut h = harness(app); | ||||||||||||||||
| h.run_steps(3); | ||||||||||||||||
| let long = "x".repeat(2001); | ||||||||||||||||
| let mark = h.state().session.notice_mark(); | ||||||||||||||||
| h.get_by_role(Role::MultilineTextInput).type_text(&long); | ||||||||||||||||
| h.run_steps(2); | ||||||||||||||||
| h.get_by_role_and_label(Role::CheckBox, "Bold").focus(); | ||||||||||||||||
| h.run_steps(3); | ||||||||||||||||
| let saved = |app: &RustGisApp| graphics::label(&app.session.map().layer(layer).unwrap().dataset, row).unwrap().to_owned(); | ||||||||||||||||
| assert_eq!(saved(h.state()), "Old"); | ||||||||||||||||
| assert_eq!(h.get_by_role(Role::MultilineTextInput).value().as_deref(), Some(long.as_str())); | ||||||||||||||||
| assert_eq!(h.state().session.notices_since(mark).iter().filter(|n| n.error).count(), 1); | ||||||||||||||||
| h.get_by_role(Role::MultilineTextInput).focus(); | ||||||||||||||||
| h.run_steps(2); | ||||||||||||||||
| h.key_press(egui::Key::End); | ||||||||||||||||
| h.key_press(egui::Key::Backspace); | ||||||||||||||||
| h.run_steps(2); | ||||||||||||||||
| h.get_by_role_and_label(Role::CheckBox, "Bold").focus(); | ||||||||||||||||
| h.run_steps(3); | ||||||||||||||||
| assert_eq!(saved(h.state()), "x".repeat(2000)); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /// The map with the text being typed moves (its tab, Move Up, `map.move`) and stays in view: the | ||||||||||||||||
| /// pane keeps the text and saves it when it ends, instead of dropping it for "another map" (#2959). | ||||||||||||||||
| #[test] | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep the refused text when the Text section is folded.
Folding Text after a rejected edit discards that edit.
textform::sectionreturnsNonewhile the section is closed, so theelse { return; }after the call exits before the refused state is stored again. Reopening Text then shows the saved label, not the rejected text.Restore the filtered
refusedvalue before this return. The existing filter still drops stale refusals.Suggested fix
Committable suggestion