瀏覽代碼

format json on change

AykutSarac 2 年之前
父節點
當前提交
e27da0df1b
共有 2 個文件被更改,包括 7 次插入6 次删除
  1. 5 4
      src/hooks/useFocusNode.tsx
  2. 2 2
      src/store/useJson.tsx

+ 5 - 4
src/hooks/useFocusNode.tsx

@@ -39,12 +39,13 @@ export const useFocusNode = () => {
 
 
       const newPositionX =
       const newPositionX =
         (ref.offsetLeft - x) * newScale +
         (ref.offsetLeft - x) * newScale +
-        ref.clientWidth / 10 -
-        matchedNode.getBoundingClientRect().width / 10;
+        ref.clientWidth / 4 -
+        matchedNode.getBoundingClientRect().width / 4;
+
       const newPositionY =
       const newPositionY =
         (ref.offsetLeft - y) * newScale +
         (ref.offsetLeft - y) * newScale +
-        ref.clientHeight / 10 -
-        matchedNode.getBoundingClientRect().height / 10;
+        ref.clientHeight / 4 -
+        matchedNode.getBoundingClientRect().height / 4;
 
 
       highlightMatchedNodes(matchedNodes, selectedNode);
       highlightMatchedNodes(matchedNodes, selectedNode);
       setNodeCount(matchedNodes.length);
       setNodeCount(matchedNodes.length);

+ 2 - 2
src/store/useJson.tsx

@@ -84,8 +84,8 @@ const useJson = create<JsonStates & JsonActions>()((set, get) => ({
     }
     }
   },
   },
   setJson: json => {
   setJson: json => {
-    useGraph.getState().setGraph(json);
-    set({ json, hasChanges: true });
+    useGraph.getState().setGraph(json);    
+    set({ json: JSON.stringify(JSON.parse(json), null, 2), hasChanges: true });
   },
   },
   saveJson: async (isNew = true) => {
   saveJson: async (isNew = true) => {
     try {
     try {