瀏覽代碼

fix: using stale state when switching tools (#4989)

David Luzar 3 年之前
父節點
當前提交
f2d2f97546
共有 1 個文件被更改,包括 7 次插入3 次删除
  1. 7 3
      src/components/Actions.tsx

+ 7 - 3
src/components/Actions.tsx

@@ -219,13 +219,17 @@ export const ShapesSwitcher = ({
           penMode: true,
         });
       }
+      const nextActiveTool = { ...activeTool, type: activeToolType };
       setAppState({
-        activeTool: { ...activeTool, type: activeToolType },
+        activeTool: nextActiveTool,
         multiElement: null,
         selectedElementIds: {},
       });
-      setCursorForShape(canvas, { ...appState, activeTool });
-      if (activeTool.type === "image") {
+      setCursorForShape(canvas, {
+        ...appState,
+        activeTool: nextActiveTool,
+      });
+      if (activeToolType === "image") {
         onImageAction({ pointerType });
       }
     },