Merge pull request #10019 from dotCooCoo/fix/speed-i13853-layers

Layers: the selection squares read held art from the listed rows
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 17:28:42 -08:00
commit a836ddd7a7
4 files changed
+67 -7

No files matched your search

+3 -7
View File
@@ -357,15 +357,11 @@ impl Component for Cells {
/// The marks of node row `n`'s selection square in the panel over `tree`: whether it shows the
/// full-sized square (the row is selected, or it is a layer or sublayer whose visible, unlocked art
/// is all selected), and whether it shows the small one (it holds selected art otherwise).
/// is all selected), and whether it shows the small one (it holds selected art otherwise). It reads
/// the nodes that hold selected art from the rows, which list them once per revision.
pub(super) fn square_marks(tree: &DocLayers<'_>, n: &Node) -> (bool, bool) {
let full = tree.is_selected(n.id) || tree.is_full(n.id);
let holds = !full && {
let mut any = false;
n.walk(&mut |c| any |= c.id != n.id && tree.is_selected(c.id));
any
};
(full, holds)
(full, !full && tree.holds_selected(n.id))
}
/// The cells of row `row` (shown as `info`) of the panel over `tree`.
@@ -193,6 +193,9 @@ pub(super) struct LayerRows {
/// and not empty.
#[plain_data(assume = "node ids are integers")]
full: HashSet<NodeId>,
/// The nodes that hold a selected object below them ([`super::rows::holding`]).
#[plain_data(assume = "node ids are integers")]
holding: HashSet<NodeId>,
/// The selected blends, in selection order.
#[plain_data(assume = "node ids are integers")]
blends: Vec<NodeId>,
@@ -252,6 +255,7 @@ impl LayerRows {
ruler,
guide_rows,
full: super::rows::full_layers(doc, &selected),
holding: super::rows::holding(doc, &selected),
selected,
blends: blends.collect(),
root: st.isolation.and_then(|i| isolated_root(doc, i)).map(|(n, ..)| n.id),
@@ -310,6 +314,11 @@ impl LayerRows {
self.full.contains(&id)
}
/// Whether node `id` holds a selected object below it.
pub(super) fn holds_selected(&self, id: NodeId) -> bool {
self.holding.contains(&id)
}
/// The node ids a row menu's command acts on: every highlighted row when the menu's row is one of
/// them, else the row's own node.
pub(super) fn targets(&self, target: &MenuTarget<RowId>) -> Vec<u64> {
+31
View File
@@ -150,6 +150,37 @@ pub(super) fn full_layers(doc: &Document, sel: &HashSet<NodeId>) -> HashSet<Node
out
}
#[cfg(test)]
thread_local! {
/// How many nodes [`holding`] visited on this thread.
pub(super) static HOLDING_VISITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}
/// The nodes of `doc` that hold an object of `sel` below them, found in one pass over the tree: the rows whose
/// selection square shows the small mark when they are not full.
pub(super) fn holding(doc: &Document, sel: &HashSet<NodeId>) -> HashSet<NodeId> {
/// Adds `n` to `out` when an object of `sel` is below it, and returns whether `n` or one below it is in `sel`.
fn visit(n: &Node, sel: &HashSet<NodeId>, out: &mut HashSet<NodeId>) -> bool {
#[cfg(test)]
HOLDING_VISITS.with(|v| v.set(v.get() + 1));
let mut below = false;
for c in n.children().into_iter().flatten() {
below |= visit(c, sel, out);
}
if below {
out.insert(n.id);
}
below || sel.contains(&n.id)
}
let mut out = HashSet::new();
if !sel.is_empty() {
for n in &doc.layers {
visit(n, sel, &mut out);
}
}
out
}
/// The `layer.target` of a click with `mods` on the target circle of `id`, by the rules of a row click (#8639): plain
/// targets it, Ctrl/Cmd adds it to the selection or takes it out, Shift selects the art of every row `filter` lists
/// from `anchor` (the last circle clicked, else the targeted row) to it, and Shift+Ctrl/Cmd adds that art. With it,
+24
View File
@@ -1328,3 +1328,27 @@ fn a_target_circle_drop_after_file_revert_leaves_the_restored_appearance_in_plac
panel.drag("Target A", "Target B", Modifiers::NONE);
assert_eq!(fill(&panel.app(), b), red, "a target circle drag started after the revert still moves the appearance");
}
/// The rows find which nodes hold selected art once per revision: frames that change nothing walk no node for the
/// selection squares, and a new selection walks the tree once.
#[test]
fn idle_frames_walk_no_node_for_the_selection_squares() {
use crate::tests::panel_harness::Panel;
let visits = || super::rows::HOLDING_VISITS.with(std::cell::Cell::get);
let (mut app, [layer, sub, g, b, a, c]) = nested();
app.session.execute("select.set", &json!({"ids": [b.0]})).unwrap();
let mut panel = Panel::new(app, show);
panel.frame();
assert_eq!(squares(&panel.app(), &[layer, sub, g, b, a, c]), (vec![b], vec![layer, sub, g]), "the layers and the group hold B");
let before = visits();
for _ in 0..10 {
panel.frame();
}
assert_eq!(visits() - before, 0, "frames that change nothing walk no node");
panel.app().session.execute("select.set", &json!({"ids": [a.0]})).unwrap();
let before = visits();
for _ in 0..5 {
panel.frame();
}
assert!((1..=12).contains(&(visits() - before)), "a new selection walks the tree once: {}", visits() - before);
}