From dea55cbaf066133ddf60fa641f62a9cc4b64824f Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Sun, 29 Nov 2026 03:09:27 +0100 Subject: [PATCH] Reuse cached text bounds during layer picking --- crates/engine-paint/src/cmd/pick_cmds.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/engine-paint/src/cmd/pick_cmds.rs b/crates/engine-paint/src/cmd/pick_cmds.rs index 4ed5bb7b05..0829d2e830 100644 --- a/crates/engine-paint/src/cmd/pick_cmds.rs +++ b/crates/engine-paint/src/cmd/pick_cmds.rs @@ -56,8 +56,8 @@ fn layers_hit(doc: &Document, x: i32, y: i32, type_bounds: bool) -> Vec 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]