From 1d920efe10dfb44ce856822840415cb734a91085 Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Wed, 16 Nov 2022 10:38:23 -0800 Subject: [PATCH] Change hit test to explore all nodes Summary: Previously we would only consider a node hit if the nouse pos was inside every parents. There are a few reason why this isnt ideal: 1. Fragments are return 0 bounds 2. Many hierachys (particually in litho ) have nonsensical strucutres where your parent may have hieght 0, or children overflow parents bounds. Therefore it was impossible to select many nodes but unclear why Reviewed By: lblasa Differential Revision: D41304499 fbshipit-source-id: d75c8060f71fa0b972f136cb11258b62a9c98ebc --- .../components/Visualization2D.tsx | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx b/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx index 3e1fc2f84..40d0cc704 100644 --- a/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx +++ b/desktop/plugins/public/ui-debugger/components/Visualization2D.tsx @@ -301,27 +301,26 @@ function hitTest(node: NestedNode, mouseCoordinate: Coordinate): NestedNode[] { function hitTestRec(node: NestedNode, mouseCoordinate: Coordinate): boolean { const nodeBounds = node.bounds; - if (boundsContainsCoordinate(nodeBounds, mouseCoordinate)) { - let children = node.children; + const thisNodeHit = boundsContainsCoordinate(nodeBounds, mouseCoordinate); - if (node.activeChildIdx != null) { - children = [node.children[node.activeChildIdx]]; - } - const offsetMouseCoord = offsetCoordinate(mouseCoordinate, nodeBounds); - let childHit = false; + let children = node.children; - for (const child of children) { - childHit = hitTestRec(child, offsetMouseCoord) || childHit; - } + if (node.activeChildIdx != null) { + children = [node.children[node.activeChildIdx]]; + } + const offsetMouseCoord = offsetCoordinate(mouseCoordinate, nodeBounds); + let childHit = false; - if (!childHit) { - res.push(node); - } - - return true; + for (const child of children) { + childHit = hitTestRec(child, offsetMouseCoord) || childHit; } - return false; + const hit = thisNodeHit && !childHit; + if (hit) { + res.push(node); + } + + return hit; } hitTestRec(node, mouseCoordinate);