Reuse cached text bounds during layer picking

This commit is contained in:
FredApps committed 2026-11-29 03:09:27 +01:00
1 parent f7d76f5be4
commit dea55cbaf0
1 file changed
+13 -2
+13 -2
View File
@@ -56,8 +56,8 @@ fn layers_hit(doc: &Document, x: i32, y: i32, type_bounds: bool) -> Vec<LayerId>
let alpha = match &l.content {
// Fill layers cover the canvas (their mask limits them).
LayerContent::Fill(_) => 1.0,
// The text's pixel bounds (in document space, so they follow the layer's transform).
LayerContent::Text(t) if type_bounds && t.cache.as_ref().is_some_and(|c| c.content_bounds().contains(x, y)) => 1.0,
// Reuse the compositor's tile-identity cache for text bounds: pointer movement must not rescan unchanged glyph pixels.
LayerContent::Text(t) if type_bounds && t.cache.as_ref().is_some_and(|c| photocraft_compose::bounds::content_bounds(c).contains(x, y)) => 1.0,
_ => match l.surface() {
Some(s) => {
let mut px = [[0.0f32; 4]; 1];
@@ -416,6 +416,17 @@ mod tests {
let list = s.execute("layer.pickAt", json!({"x": 17, "y": 15, "list": true})).unwrap();
assert_eq!(list["layers"][0]["layer"], t.0);
assert_eq!(list["layers"][1]["layer"], bg.0);
// A new text rendering changes tile identity; undo restores the old cached bounds.
assert_eq!(pick(&mut s, 28, 15), bg.0, "outside the original text");
s.edit("extend type", |doc, _| {
let LayerContent::Text(text) = &mut doc.layer_mut(t).unwrap().content else { panic!("text layer") };
text.cache.as_mut().unwrap().fill_rect(Rect::new(30, 10, 34, 20), &[0.0, 0.0, 0.0, 1.0]);
Ok(())
})
.unwrap();
assert_eq!(pick(&mut s, 28, 15), t.0, "inside the expanded glyph bounds");
assert!(s.undo());
assert_eq!(pick(&mut s, 28, 15), bg.0, "undo restores the original bounds");
}
#[test]