Check layer.setExpanded's precondition without a walk

Any nested group sits inside a top-level one, so the top-level layers tell
whether a document has a group. The Layers panel's command states ask this
precondition every frame, and it was the last per-frame walk the idle trial
counted; the trial now expects none.
This commit is contained in:
aiongg committed 2026-11-19 20:56:48 +00:00
1 parent abedab1e4d
commit 7e13375f52
2 files changed
+6 -12

No files matched your search

+2 -1
View File
@@ -20,7 +20,8 @@ fn bad(msg: impl Into<String>) -> EngineError {
fn has_group(s: &Session) -> std::result::Result<(), String> {
let d = s.active().ok_or("no document open")?;
if d.doc.walk().iter().any(|(_, _, l)| l.is_group()) { Ok(()) } else { Err("the document has no layer groups".into()) }
// Groups hold every nested group, so a document with any group has one at the top level.
if d.doc.layers.iter().any(|l| l.is_group()) { Ok(()) } else { Err("the document has no layer groups".into()) }
}
fn opt_bool(p: &Value, key: &str) -> Result<Option<bool>> {
+4 -11
View File
@@ -136,9 +136,7 @@ fn layers_rows_follow_renames_and_both_toggles() {
/// With the status bar, the document tabs, the Layers and History panels, an artboard's pasteboard and the Move
/// tool's snapping on screen, a frame that changes nothing walks no document, rebuilds no layer index and computes
/// no derived value (title, status, pages, uncovered work, moving layers, History rows); after an edit they are
/// computed again once, and the next idle frames compute none. 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.
/// computed again once, and the next idle frames compute none.
#[test]
fn idle_frames_walk_no_document() {
let mut s = Session::new();
@@ -159,14 +157,9 @@ fn idle_frames_walk_no_document() {
h.run_steps(4);
let serial = |h: &H| h.state().session.active().unwrap().doc.layers.index().serial();
let builds = |h: &H| h.state().doc_queries.builds();
let states = |h: &H| {
let walks = photocraft_doc::walks();
drop(crate::panels::registry::states(h.state()));
photocraft_doc::walks() - walks
};
let (walks, index, built) = (photocraft_doc::walks(), serial(&h), builds(&h));
h.run_steps(10);
assert_eq!((photocraft_doc::walks() - walks, serial(&h)), (10 * states(&h), index), "idle frames walk nothing outside the command states");
assert_eq!((photocraft_doc::walks() - walks, serial(&h)), (0, index), "idle frames walk nothing");
assert_eq!(builds(&h), built, "idle frames compute nothing");
// The new artboard is the active layer; the fill goes on a pixel layer.
@@ -176,8 +169,8 @@ fn idle_frames_walk_no_document() {
h.state_mut().run("edit.fill", json!({"contents": "black"})).unwrap();
h.run_steps(4);
assert!(builds(&h) > built, "an edit computes the values again");
let (per_frame, walks, built) = (states(&h), photocraft_doc::walks(), builds(&h));
let (walks, built) = (photocraft_doc::walks(), builds(&h));
h.run_steps(10);
assert_eq!(photocraft_doc::walks() - walks, 10 * per_frame, "after an edit, idle frames walk nothing again");
assert_eq!(photocraft_doc::walks() - walks, 0, "after an edit, idle frames walk nothing again");
assert_eq!(builds(&h), built, "after an edit, idle frames compute nothing again");
}