Pārlūkot izejas kodu

improve search node algorithm

AykutSarac 3 gadi atpakaļ
vecāks
revīzija
a029bbe73d
1 mainītis faili ar 12 papildinājumiem un 4 dzēšanām
  1. 12 4
      src/containers/LiveEditor/index.tsx

+ 12 - 4
src/containers/LiveEditor/index.tsx

@@ -77,13 +77,21 @@ export const LiveEditor: React.FC = React.memo(() => {
       `span[data-key*='${settings.searchNode}' i]`
     );
 
-    if (wrapperRect && node) {
-      const newScale = 0.8;
+    document
+      .querySelector("foreignObject.searched")
+      ?.classList.remove("searched");
+
+    if (wrapperRect && node && node.parentElement) {
+      const newScale = 1.2;
       const x = Number(node.getAttribute("data-x"));
       const y = Number(node.getAttribute("data-y"));
 
-      const newPositionX = (wrapperRect.left - x) * newScale;
-      const newPositionY = (wrapperRect.top - y) * newScale;
+      const newPositionX = (wrapperRect.left - x) * newScale - 300;
+      const newPositionY = (wrapperRect.top - y) * newScale + 300;
+
+      node.parentElement.parentElement
+        ?.closest("foreignObject")
+        ?.classList.toggle("searched");
 
       wrapperRef.current?.setTransform(newPositionX, newPositionY, newScale);
     }