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
This commit is contained in:
Luke De Feo
2022-11-16 10:38:23 -08:00
committed by Facebook GitHub Bot
parent 53c15b2e59
commit 1d920efe10

View File

@@ -301,27 +301,26 @@ function hitTest(node: NestedNode, mouseCoordinate: Coordinate): NestedNode[] {
function hitTestRec(node: NestedNode, mouseCoordinate: Coordinate): boolean { function hitTestRec(node: NestedNode, mouseCoordinate: Coordinate): boolean {
const nodeBounds = node.bounds; const nodeBounds = node.bounds;
if (boundsContainsCoordinate(nodeBounds, mouseCoordinate)) { const thisNodeHit = boundsContainsCoordinate(nodeBounds, mouseCoordinate);
let children = node.children;
if (node.activeChildIdx != null) { let children = node.children;
children = [node.children[node.activeChildIdx]];
}
const offsetMouseCoord = offsetCoordinate(mouseCoordinate, nodeBounds);
let childHit = false;
for (const child of children) { if (node.activeChildIdx != null) {
childHit = hitTestRec(child, offsetMouseCoord) || childHit; children = [node.children[node.activeChildIdx]];
} }
const offsetMouseCoord = offsetCoordinate(mouseCoordinate, nodeBounds);
let childHit = false;
if (!childHit) { for (const child of children) {
res.push(node); childHit = hitTestRec(child, offsetMouseCoord) || childHit;
}
return true;
} }
return false; const hit = thisNodeHit && !childHit;
if (hit) {
res.push(node);
}
return hit;
} }
hitTestRec(node, mouseCoordinate); hitTestRec(node, mouseCoordinate);