浏览代码

Different call of resumeRecording() (#636)

Instead of finding all the places where we want to resume recording, we should do it after every componentDidUpdate(). The idea is that we just want to disable the history for certain setState, for which we call directly before skipHistory.
Christopher Chedeau 5 年之前
父节点
当前提交
637276301a
共有 1 个文件被更改,包括 12 次插入21 次删除
  1. 12 21
      src/index.tsx

+ 12 - 21
src/index.tsx

@@ -843,10 +843,10 @@ export class App extends React.Component<any, AppState> {
                   lastY = e.clientY;
                   lastY = e.clientY;
                   // We don't want to save history when panning around
                   // We don't want to save history when panning around
                   history.skipRecording();
                   history.skipRecording();
-                  this.setState(state => ({
-                    scrollX: state.scrollX - deltaX,
-                    scrollY: state.scrollY - deltaY,
-                  }));
+                  this.setState({
+                    scrollX: this.state.scrollX - deltaX,
+                    scrollY: this.state.scrollY - deltaY,
+                  });
                 };
                 };
                 const teardown = (lastMouseUp = () => {
                 const teardown = (lastMouseUp = () => {
                   lastMouseUp = null;
                   lastMouseUp = null;
@@ -855,7 +855,6 @@ export class App extends React.Component<any, AppState> {
                   if (!isHoldingSpace) {
                   if (!isHoldingSpace) {
                     setCursorForShape(this.state.elementType);
                     setCursorForShape(this.state.elementType);
                   }
                   }
-                  history.resumeRecording();
                   window.removeEventListener("mousemove", onMouseMove);
                   window.removeEventListener("mousemove", onMouseMove);
                   window.removeEventListener("mouseup", teardown);
                   window.removeEventListener("mouseup", teardown);
                   window.removeEventListener("blur", teardown);
                   window.removeEventListener("blur", teardown);
@@ -1060,7 +1059,7 @@ export class App extends React.Component<any, AppState> {
                   const dx = x - lastX;
                   const dx = x - lastX;
                   // We don't want to save history when scrolling
                   // We don't want to save history when scrolling
                   history.skipRecording();
                   history.skipRecording();
-                  this.setState(state => ({ scrollX: state.scrollX - dx }));
+                  this.setState({ scrollX: this.state.scrollX - dx });
                   lastX = x;
                   lastX = x;
                   return;
                   return;
                 }
                 }
@@ -1070,7 +1069,7 @@ export class App extends React.Component<any, AppState> {
                   const dy = y - lastY;
                   const dy = y - lastY;
                   // We don't want to save history when scrolling
                   // We don't want to save history when scrolling
                   history.skipRecording();
                   history.skipRecording();
-                  this.setState(state => ({ scrollY: state.scrollY - dy }));
+                  this.setState({ scrollY: this.state.scrollY - dy });
                   lastY = y;
                   lastY = y;
                   return;
                   return;
                 }
                 }
@@ -1277,7 +1276,6 @@ export class App extends React.Component<any, AppState> {
                   this.setState({
                   this.setState({
                     draggingElement: null,
                     draggingElement: null,
                   });
                   });
-                  history.resumeRecording();
                   return;
                   return;
                 }
                 }
 
 
@@ -1319,7 +1317,6 @@ export class App extends React.Component<any, AppState> {
                   // if no element is clicked, clear the selection and redraw
                   // if no element is clicked, clear the selection and redraw
                   elements = clearSelection(elements);
                   elements = clearSelection(elements);
                   this.setState({});
                   this.setState({});
-                  history.resumeRecording();
                   return;
                   return;
                 }
                 }
 
 
@@ -1341,9 +1338,6 @@ export class App extends React.Component<any, AppState> {
                     draggingElement: null,
                     draggingElement: null,
                   });
                   });
                 }
                 }
-
-                history.resumeRecording();
-                this.setState({});
               };
               };
 
 
               lastMouseUp = onMouseUp;
               lastMouseUp = onMouseUp;
@@ -1517,15 +1511,10 @@ export class App extends React.Component<any, AppState> {
     const { deltaX, deltaY } = e;
     const { deltaX, deltaY } = e;
     // We don't want to save history when panning around
     // We don't want to save history when panning around
     history.skipRecording();
     history.skipRecording();
-    this.setState(
-      state => ({
-        scrollX: state.scrollX - deltaX,
-        scrollY: state.scrollY - deltaY,
-      }),
-      () => {
-        history.resumeRecording();
-      },
-    );
+    this.setState({
+      scrollX: this.state.scrollX - deltaX,
+      scrollY: this.state.scrollY - deltaY,
+    });
   };
   };
 
 
   private addElementsFromPaste = (paste: string) => {
   private addElementsFromPaste = (paste: string) => {
@@ -1619,6 +1608,8 @@ export class App extends React.Component<any, AppState> {
           elements,
           elements,
         ),
         ),
       );
       );
+    } else {
+      history.resumeRecording();
     }
     }
   }
   }
 }
 }