From 6dd2efccf51966a80ba90972d4882a8dd985d9d8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 11:29:53 -0800 Subject: [PATCH] Links: a confined links.marked call leaves the canvas markers alone With Show Missing Links on, a links.marked call from a caller confined to other read folders saw a linked file outside them as missing and wrote that answer to the markers the canvas draws, putting a missing-link badge on a file that is there. The call now updates the markers only when its read folders match those the document was opened with and no script gate is in force; otherwise the caller gets its own answer. --- crates/engine/src/cmd/links.rs | 16 ++++++++++++++-- crates/engine/src/file_access.rs | 7 +++++++ crates/engine/src/tests/missing_links.rs | 21 +++++++++++++++++++++ docs/mcp.md | 2 ++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/crates/engine/src/cmd/links.rs b/crates/engine/src/cmd/links.rs index 62a84418b0..e6de3f1cdd 100644 --- a/crates/engine/src/cmd/links.rs +++ b/crates/engine/src/cmd/links.rs @@ -44,7 +44,7 @@ pub fn specs() -> Vec { "{on?: bool (default: toggle)} show non-printing red outlines and badges on missing linked images and placed documents in the active document; transient view state, no undo step; reads no files (the desktop app scans in the background, links.marked inspects now) → {on}", has_doc, show_missing_links), cmd!(query "links.marked", "Marked Missing Links", [], None, - "{} inspect missing links now; only visible image objects and placed documents are marked, and none when the toggle is off → {on, images: [{id, bounds: [x0, y0, x1, y1]}]}", + "{} inspect missing links now; only visible image objects and placed documents are marked, and none when the toggle is off; a caller whose read folders differ from the document's gets its own answer and the canvas markers stay as they are → {on, images: [{id, bounds: [x0, y0, x1, y1]}]}", has_doc, marked), cmd!( query "links.check", @@ -2693,7 +2693,19 @@ fn marked(s: &mut Session, _: &Value) -> Result { Some(json!({"id": id.0, "bounds": [b.x0, b.y0, b.x1, b.y1]})) }) .collect(); - st.missing_link_markers = Some((st.doc.clone(), ids)); + // The canvas draws the markers the link watch finds with the read roots the document was + // opened with ([`Session::start_link_scan`]). An answer found with other read roots stays the + // caller's, as is one found by a script command, whose file-read gate the link watch does + // not have. + let same_roots = !crate::file_access::in_script_command() + && match (crate::file_access::current(), &st.opened_by) { + (None, None) => true, + (Some(a), Some(b)) => Arc::ptr_eq(&a, b) || a.same_reads(b), + _ => false, + }; + if same_roots { + st.missing_link_markers = Some((st.doc.clone(), ids)); + } Ok(json!({"on": st.show_missing_links, "images": images})) } diff --git a/crates/engine/src/file_access.rs b/crates/engine/src/file_access.rs index 0c8831c9ab..f96f274054 100644 --- a/crates/engine/src/file_access.rs +++ b/crates/engine/src/file_access.rs @@ -163,6 +163,13 @@ impl AutomationRoots { within(&self.read, &other.read) && within(&self.write, &other.write) } + /// Whether these roots and `other` let the same files be read: each read root of either lies + /// inside a read root of the other. + pub(crate) fn same_reads(&self, other: &Self) -> bool { + let within = |mine: &[Root], theirs: &[Root]| theirs.iter().all(|o| mine.iter().any(|r| inside(&o.resolved, &r.resolved))); + within(&self.read, &other.read) && within(&other.read, &self.read) + } + /// The roots for people: `read A, B; write C` (`none` for a kind without any). pub fn describe(&self) -> String { let list = |roots: &[Root]| { diff --git a/crates/engine/src/tests/missing_links.rs b/crates/engine/src/tests/missing_links.rs index e74d9fe545..0e2b0ff2d7 100644 --- a/crates/engine/src/tests/missing_links.rs +++ b/crates/engine/src/tests/missing_links.rs @@ -76,6 +76,27 @@ fn missing_link_markers_follow_files_relink_update_and_embed() { assert!(marked(&mut s).is_empty()); } +/// A caller confined to other folders sees a linked file outside them as missing, but its answer +/// does not replace the markers drawn on the canvas. +#[test] +fn a_confined_marked_query_leaves_the_canvas_markers_alone() { + let dir = Folder::new("marker-confined"); + let path = dir.file("art.png"); + write(&path, &png(40, 40, RED)); + let other = dir.0.join("other"); + std::fs::create_dir_all(&other).unwrap(); + let mut s = session(); + let id = place(&mut s, &path); + s.execute("view.showMissingLinks", &json!({"on": true})).unwrap(); + assert!(marked(&mut s).is_empty()); + let roots = crate::file_access::AutomationRoots::new(&[other.as_path()], &[]).unwrap(); + assert_eq!(crate::file_access::confine(roots.as_ref(), || marked(&mut s)), vec![id.0], "the caller cannot read the file"); + assert!(s.doc().unwrap().marked_missing_links().is_empty(), "the canvas keeps no marker for a file that is there"); + std::fs::remove_file(&path).unwrap(); + assert_eq!(marked(&mut s), vec![id.0]); + assert_eq!(s.doc().unwrap().marked_missing_links(), vec![id]); +} + #[test] fn missing_link_worker_refreshes_without_the_panel_and_ignores_old_art() { for mode in ["automatically", "askWhenModified", "manually"] { diff --git a/docs/mcp.md b/docs/mcp.md index 909492ea55..821e58a521 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -74,6 +74,8 @@ Use `run_command` with these engine commands (the `command_run` alias takes the `links.marked` refreshes file status and returns `{on, images: [{id, bounds: [x0, y0, x1, y1]}]}` for visible missing linked images and placed documents in the active document. +A caller whose read folders differ from those the document was opened with gets the files it +can read checked, and the markers on the canvas stay as they are. When the toggle is off, `images` is empty; `links.list {show: "missing"}` still lists missing links independently. Neither command changes selection or undo history. `view.showMissingLinks` never reads linked files, so it returns at once even for a large or slow file; `links.marked` is