diff --git a/src/components/App.tsx b/src/components/App.tsx index ac1746a4..25d25a36 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -272,6 +272,7 @@ export type ExcalidrawImperativeAPI = | { updateScene: InstanceType["updateScene"]; resetScene: InstanceType["resetScene"]; + resetHistory: InstanceType["resetHistory"]; getSceneElementsIncludingDeleted: InstanceType< typeof App >["getSceneElementsIncludingDeleted"]; @@ -311,6 +312,7 @@ class App extends React.Component { forwardedRef.current = { updateScene: this.updateScene, resetScene: this.resetScene, + resetHistory: this.resetHistory, getSceneElementsIncludingDeleted: this.getSceneElementsIncludingDeleted, }; } @@ -555,6 +557,10 @@ class App extends React.Component { } }; + private resetHistory = () => { + history.clear(); + }; + /** Completely resets scene & history. * Do not use for clear scene user action. */ private resetScene = withBatchedUpdates(() => { @@ -564,7 +570,7 @@ class App extends React.Component { appearance: this.state.appearance, username: this.state.username, }); - history.clear(); + this.resetHistory(); }); private initializeScene = async () => { @@ -665,7 +671,7 @@ class App extends React.Component { ), }; } - history.clear(); + this.resetHistory(); this.syncActionResult({ ...scene, commitToHistory: true, @@ -1314,6 +1320,12 @@ class App extends React.Component { this.updateScene({ elements: newElements }); + // We haven't yet implemented multiplayer undo functionality, so we clear the undo stack + // when we receive any messages from another peer. This UX can be pretty rough -- if you + // undo, a user makes a change, and then try to redo, your element(s) will be lost. However, + // right now we think this is the right tradeoff. + this.resetHistory(); + if (!this.portal.socketInitialized && !initFromSnapshot) { this.initializeSocket(); } @@ -1340,12 +1352,6 @@ class App extends React.Component { } this.scene.replaceAllElements(sceneData.elements); - - // We haven't yet implemented multiplayer undo functionality, so we clear the undo stack - // when we receive any messages from another peer. This UX can be pretty rough -- if you - // undo, a user makes a change, and then try to redo, your element(s) will be lost. However, - // right now we think this is the right tradeoff. - history.clear(); }, );