Keep the frame marks and the link watcher's check off per-frame walks

The canvas's empty-frame placeholders and the link watcher's has-links check
read DocQueries, once per document revision. The walk trial counts the panels'
command states, which task a of #15709 moves onto revisions, as their own.

Part of #15709.
This commit is contained in:
aiongg committed 2026-11-19 20:13:08 +00:00
1 parent 24bdb181f9
commit 6764f138bb
4 files changed
+46 -19

No files matched your search

+28 -3
View File
@@ -1,13 +1,14 @@
//! What the chrome reads from a document at the cost of a walk or a parse, computed once per document revision:
//! the status bar's sizes and profile, the File Info copyright mark of the titles, and the pasteboard's uncovered
//! work (once per revision of the document the canvas shows).
//! the status bar's sizes and profile, the File Info copyright mark of the titles, the empty frames the canvas marks,
//! whether linked files need watching, and the pasteboard's uncovered work (once per revision of the document the
//! canvas shows).
use std::collections::HashMap;
use std::sync::{Arc, Mutex, PoisonError};
use craft::behavior::kurbo::Rect as DocRect;
use craft::ui::bars::StatusValues;
use photocraft_doc::DocId;
use photocraft_doc::{DocId, LayerId};
use photocraft_engine::{DocState, Session};
use crate::i18n::Lang;
@@ -30,6 +31,8 @@ struct Entry {
/// The status values about the document, in the language they were written in.
status: Option<(Lang, StatusValues)>,
copyrighted: Option<bool>,
empty_frames: Option<Arc<[LayerId]>>,
has_links: Option<bool>,
/// The uncovered rects and the display revision of the document they were measured on.
uncovered: Option<(u64, Arc<[DocRect]>)>,
}
@@ -64,6 +67,28 @@ impl DocQueries {
self.with(session, st, |entry| *entry.copyrighted.get_or_insert_with(|| photocraft_engine::file_cmds::copyright_marked(st.doc.metadata.xmp.as_deref())))
}
/// The visible frames of `st` with nothing placed in them, which the canvas marks with a placeholder.
pub(crate) fn empty_frames(&self, session: &Session, st: &DocState) -> Arc<[LayerId]> {
self.with(session, st, |entry| {
entry
.empty_frames
.get_or_insert_with(|| {
let doc = &st.doc;
doc.walk()
.into_iter()
.filter(|(path, _, l)| l.frame.is_some() && l.children().is_some_and(<[_]>::is_empty) && doc.shown_at(path))
.map(|(_, _, l)| l.id)
.collect()
})
.clone()
})
}
/// Whether `st` has linked smart objects, whose files the link watcher scans.
pub(crate) fn has_linked_files(&self, session: &Session, st: &DocState) -> bool {
self.with(session, st, |entry| *entry.has_links.get_or_insert_with(|| !photocraft_engine::link_watch::linked_files(&st.doc).is_empty()))
}
/// Where the shown layers draw outside the artboards of `st`, for the document the canvas shows at display
/// revision `shown`, `compute`d when either changes.
pub(crate) fn uncovered(&self, session: &Session, st: &DocState, shown: u64, compute: impl FnOnce() -> Vec<DocRect>) -> Arc<[DocRect]> {
+11 -4
View File
@@ -97,7 +97,9 @@ fn thumbnail_revisions_follow_only_their_own_layer() {
/// With the status bar, the document tabs, the Layers panel and the Move tool's snapping on screen, a frame that
/// changes nothing walks no document and rebuilds no layer index; after an edit the next idle frames walk none
/// either, so what the chrome derives is rebuilt once per change, not per frame.
/// either, so what the chrome derives is rebuilt once per change, not per frame. The panels' command states
/// (`panels::registry::states`, run once a frame) still ask some commands' preconditions, which walk; #15709 task a
/// moves those onto revisions, and until then the trial counts the walks of one such run per frame.
#[test]
fn idle_frames_walk_no_document() {
let mut s = Session::new();
@@ -115,14 +117,19 @@ fn idle_frames_walk_no_document() {
h.state_mut().ui.tool = Tool::Move;
h.run_steps(4);
let serial = |h: &H| h.state().session.active().unwrap().doc.layers.index().serial();
let states = |h: &H| {
let walks = photocraft_doc::walks();
drop(crate::panels::registry::states(h.state()));
photocraft_doc::walks() - walks
};
let (walks, index) = (photocraft_doc::walks(), serial(&h));
h.run_steps(10);
assert_eq!((photocraft_doc::walks() - walks, serial(&h)), (0, index), "idle frames walk nothing");
assert_eq!((photocraft_doc::walks() - walks, serial(&h)), (10 * states(&h), index), "idle frames walk nothing outside the command states");
h.state_mut().run("select.rect", json!({"x": 10, "y": 10, "width": 50, "height": 40})).unwrap();
h.state_mut().run("edit.fill", json!({"contents": "black"})).unwrap();
h.run_steps(4);
let walks = photocraft_doc::walks();
let (per_frame, walks) = (states(&h), photocraft_doc::walks());
h.run_steps(10);
assert_eq!(photocraft_doc::walks() - walks, 0, "after an edit, idle frames walk nothing again");
assert_eq!(photocraft_doc::walks() - walks, 10 * per_frame, "after an edit, idle frames walk nothing again");
}
+1 -1
View File
@@ -178,7 +178,7 @@ fn link_updates(app: &mut PhotocraftApp, ctx: &egui::Context) {
let focused = ctx.input(|i| i.focused);
let was_focused: bool = ctx.data(|d| d.get_temp(focus_key)).unwrap_or(focused);
ctx.data_mut(|d| d.insert_temp(focus_key, focused));
let has_links = app.session.active().is_some_and(|d| !photocraft_engine::link_watch::linked_files(&d.doc).is_empty());
let has_links = app.session.active().is_some_and(|d| app.doc_queries.has_linked_files(&app.session, d));
if !has_links {
return;
}
+6 -11
View File
@@ -689,17 +689,12 @@ pub(crate) fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, rect: egui::Rect)
let t = Tokens::get(ui.ctx());
let painter = ui.painter().clone();
if let Some(st) = app.session.active() {
for (path, _, l) in st.doc.walk() {
if !path_visible(&st.doc, &path) {
continue;
}
let Some(f) = &l.frame else { continue };
if l.children().is_some_and(|c| c.is_empty()) {
let q = f.corners().map(|p| view.to_screen(KPoint::new(p.x, p.y)));
paint_path(&painter, &view, &f.outline(), Stroke::new(1., t.text_faint));
painter.line_segment([q[0], q[2]], Stroke::new(1., t.text_faint));
painter.line_segment([q[1], q[3]], Stroke::new(1., t.text_faint));
}
for id in app.doc_queries.empty_frames(&app.session, st).iter() {
let Some(f) = st.doc.layer(*id).and_then(|l| l.frame.as_ref()) else { continue };
let q = f.corners().map(|p| view.to_screen(KPoint::new(p.x, p.y)));
paint_path(&painter, &view, &f.outline(), Stroke::new(1., t.text_faint));
painter.line_segment([q[0], q[2]], Stroke::new(1., t.text_faint));
painter.line_segment([q[1], q[3]], Stroke::new(1., t.text_faint));
}
}
if app.ui.tool != Tool::Frame || app.ui.transform.is_some() {