diff --git a/src/store/index.ts b/src/store/index.ts index 818acfd0..78ee6e8b 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -200,6 +200,14 @@ const storeModel: StoreModel = { selection, state.transform ); + + if (!selectedNodes.length) { + state.nodesSelectionActive = false; + state.selectedElements = []; + + return; + } + const selectedNodesBbox = getRectOfNodes(selectedNodes); state.selection = selection; diff --git a/src/utils/graph.ts b/src/utils/graph.ts index 70670dbd..07a4ffdb 100644 --- a/src/utils/graph.ts +++ b/src/utils/graph.ts @@ -152,10 +152,13 @@ export const getNodesInside = ( width: rect.width / tScale, height: rect.height / tScale, }); + return nodes.filter(({ __rg: { position, width, height } }) => { const nBox = rectToBox({ ...position, width, height }); - const overlappingArea = - (Math.max(rBox.x, nBox.x) - Math.min(rBox.x2, nBox.x2)) * (Math.max(rBox.y, nBox.y) - Math.min(rBox.y2, nBox.y2)); + const xOverlap = Math.max(0, Math.min(rBox.x2, nBox.x2) - Math.max(rBox.x, nBox.x)); + const yOverlap = Math.max(0, Math.min(rBox.y2, nBox.y2) - Math.max(rBox.y, nBox.y)); + const overlappingArea = xOverlap * yOverlap; + if (partially) { return overlappingArea >= 0; }