Browse Source

Center first matched node on canvas

Burak Ozarslan 3 năm trước cách đây
mục cha
commit
5f6b97a197
1 tập tin đã thay đổi với 5 bổ sung3 xóa
  1. 5 3
      src/hooks/useFocusNode.tsx

+ 5 - 3
src/hooks/useFocusNode.tsx

@@ -45,10 +45,12 @@ export const useFocusNode = () => {
 
 
       const newPositionX =
       const newPositionX =
         (zoomPanPinch.offsetLeft - x) * newScale +
         (zoomPanPinch.offsetLeft - x) * newScale +
-        firstMatchedNode.getBoundingClientRect().width;
+        zoomPanPinch.clientWidth / 2 -
+        firstMatchedNode.getBoundingClientRect().width / 2;
       const newPositionY =
       const newPositionY =
-        (zoomPanPinch.offsetTop - y) * newScale +
-        firstMatchedNode.getBoundingClientRect().height;
+        (zoomPanPinch.offsetLeft - y) * newScale +
+        zoomPanPinch.clientHeight / 2 -
+        firstMatchedNode.getBoundingClientRect().height / 2;
 
 
       highlightMatchedNodes(matchedNodes);
       highlightMatchedNodes(matchedNodes);