From df456ce5d6e0e2b2be5e731dcf23c3f9525467fb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 16 Nov 2026 09:19:56 -0800 Subject: [PATCH] Packaging Tools: each document keeps its own Check Fold Lines result The Fold Lines panel kept one check for the whole app. Checking a second document replaced the first document's result, so switching back to the first document, unchanged since its check, showed no issues. The panel now keeps the last check of each document by its id, and each result is still shown only while its document has not changed since. Results of documents that changed or closed are dropped when the next check is stored. --- crates/ui-egui/src/addons/packaging.rs | 33 ++++++++++++++------ crates/ui-egui/src/addons/packaging/tests.rs | 22 +++++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/crates/ui-egui/src/addons/packaging.rs b/crates/ui-egui/src/addons/packaging.rs index 54f233d945..5b37b52abf 100644 --- a/crates/ui-egui/src/addons/packaging.rs +++ b/crates/ui-egui/src/addons/packaging.rs @@ -4,8 +4,9 @@ //! paths that role (`addon.packaging.setRole`). Its menu's Role Swatches… picks the swatch that //! carries a role (`addon.packaging.setRoleSwatch`). Its Check button, like the Check Fold Lines menu //! item, checks the fold lines (`addon.packaging.check`) and lists the issues found under it, each -//! with a Select button; the list is kept until the document changes. +//! with a Select button; each document's list is kept until that document changes. +use std::collections::HashMap; use std::sync::{Arc, Weak}; use egui::{Align, Layout, Sense, Ui, vec2}; @@ -31,7 +32,7 @@ pub const ROLES: &[(&str, &str)] = /// Where the panel keeps the last `addon.packaging.roles` answer (panel state). const STATE: &str = "fold-lines"; -/// Where the panel keeps the last check (panel state). +/// Where the panel keeps the last check of each document (panel state, a [`Checks`]). const CHECKED: &str = "fold-lines-check"; /// Object › Plug-ins › Packaging Tools. @@ -103,6 +104,10 @@ impl Checked { } } +/// The last check of each document, by the document's id. The checks are shared, so reading the +/// map for a frame copies no issue lists. +type Checks = HashMap>; + /// The active document's [`DocKey`]. fn doc_key(app: &VectorcraftApp) -> Option { app.session.active().map(|st| (st.uid, Arc::downgrade(&st.doc))) @@ -110,11 +115,17 @@ fn doc_key(app: &VectorcraftApp) -> Option { /// Runs `addon.packaging.check` with `p` and shows its summary in the status bar → the check, kept /// in `ctx` for the panel. -fn run_check(app: &mut VectorcraftApp, ctx: &egui::Context, p: Value) -> Option { +fn run_check(app: &mut VectorcraftApp, ctx: &egui::Context, p: Value) -> Option> { let r = app.run(CHECK, p).map_err(|e| app.status(e)).ok()?; - let checked = Checked::of(doc_key(app)?, &r); + let key = doc_key(app)?; + let uid = key.0; + let checked = Arc::new(Checked::of(key, &r)); app.status(checked.summary()); - set_pstate(ctx, CHECKED, checked.clone()); + let mut checks: Checks = pstate(ctx, CHECKED); + // A check of a document that has since changed or closed can never be shown again. + checks.retain(|_, c| c.key.as_ref().is_some_and(|(_, doc)| doc.strong_count() > 0)); + checks.insert(uid, Arc::clone(&checked)); + set_pstate(ctx, CHECKED, checks); Some(checked) } @@ -130,11 +141,13 @@ pub(crate) fn check(app: &mut VectorcraftApp, p: Value) { } /// The last check of the active document, while the document has not changed since. -fn last_check(app: &VectorcraftApp, ctx: &egui::Context) -> Option { - let checked: Checked = pstate(ctx, CHECKED); - let same = match (&checked.key, doc_key(app)) { - (Some((uid, doc)), Some((now, current))) => *uid == now && doc.ptr_eq(¤t), - _ => false, +fn last_check(app: &VectorcraftApp, ctx: &egui::Context) -> Option> { + let (now, current) = doc_key(app)?; + let mut checks: Checks = pstate(ctx, CHECKED); + let checked = checks.remove(&now)?; + let same = match &checked.key { + Some((uid, doc)) => *uid == now && doc.ptr_eq(¤t), + None => false, }; same.then_some(checked) } diff --git a/crates/ui-egui/src/addons/packaging/tests.rs b/crates/ui-egui/src/addons/packaging/tests.rs index 93fbb2b8d2..2ce5643fc3 100644 --- a/crates/ui-egui/src/addons/packaging/tests.rs +++ b/crates/ui-egui/src/addons/packaging/tests.rs @@ -212,6 +212,28 @@ fn the_check_button_checks_and_clicking_an_issue_selects_its_lines() { assert!(text.contains("No issues found.") && text.contains("Panels: 2, hinges: 1, errors: 0, warnings: 0"), "{text}"); } +#[test] +fn each_document_keeps_its_own_check() { + crate::i18n::set_current(crate::i18n::Lang::EN); + let (mut app, _) = blank(); + let ctx = egui::Context::default(); + let text = frames(&mut app, &ctx, Some("Check")); + assert!(text.contains("A cut line ends without meeting another cut line."), "{text}"); + // A second document, checked too: it has no cut lines. + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let text = frames(&mut app, &ctx, Some("Check")); + assert!(text.contains("No cut lines are in the document.") && !text.contains("A cut line ends"), "{text}"); + // Back on the first document, unchanged since its check: its issues are still listed. + assert!(app.session.set_active(0)); + let text = frames(&mut app, &ctx, None); + assert!(text.contains("A cut line ends without meeting another cut line."), "{text}"); + assert!(text.contains("Panels: 2, hinges: 1, errors: 1, warnings: 0"), "{text}"); + // And the second document's check stays its own. + assert!(app.session.set_active(1)); + let text = frames(&mut app, &ctx, None); + assert!(text.contains("No cut lines are in the document.") && !text.contains("A cut line ends"), "{text}"); +} + #[test] fn issues_and_the_summary_show_in_the_interface_language() { let (mut app, _) = blank();