diff --git a/docs/API/ExcalidrawAutomate.d.ts b/docs/API/ExcalidrawAutomate.d.ts index e509b9f..b7ace70 100644 --- a/docs/API/ExcalidrawAutomate.d.ts +++ b/docs/API/ExcalidrawAutomate.d.ts @@ -422,6 +422,7 @@ export declare class ExcalidrawAutomate { appState?: AppState; files?: BinaryFileData; commitToHistory?: boolean; + storeAction?: "capture" | "none" | "update"; }, restore?: boolean): void; /** * connect an object to the selected element in the view diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index 2c527f7..d2d365d 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -1833,7 +1833,7 @@ export class ExcalidrawAutomate { this.targetView.updateScene({ elements: el.filter((e: ExcalidrawElement) => !elToDelete.includes(e)), appState: st, - commitToHistory: true, + storeAction: "capture", }); //this.targetView.save(); return true; @@ -1951,7 +1951,7 @@ export class ExcalidrawAutomate { appState: { viewModeEnabled: !isFullscreen, }, - commitToHistory: false, + storeAction: "none", }); this.targetView.toolsPanelRef?.current?.setExcalidrawViewMode(!isFullscreen); } @@ -1986,6 +1986,7 @@ export class ExcalidrawAutomate { appState?: AppState, files?: BinaryFileData, commitToHistory?: boolean, + storeAction?: "capture" | "none" | "update", }, restore: boolean = false, ):void { @@ -1994,7 +1995,16 @@ export class ExcalidrawAutomate { errorMessage("targetView not set", "viewToggleFullScreen()"); return; } - this.targetView.updateScene(scene,restore); + if (!Boolean(scene.storeAction)) { + scene.storeAction = scene.commitToHistory ? "capture" : "none"; + } + + this.targetView.updateScene({ + elements: scene.elements, + appState: scene.appState, + files: scene.files, + storeAction: scene.storeAction, + },restore); } /** @@ -2555,7 +2565,7 @@ export class ExcalidrawAutomate { elements.splice(newZIndex, 0, elements.splice(oldZIndex, 1)[0]); this.targetView.updateScene({ elements, - commitToHistory: true, + storeAction: "capture", }); }; diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index fc24e3c..50b8ffb 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -206,7 +206,7 @@ export const addFiles = async ( view.updateScene({ elements: s.scene.elements, appState: s.scene.appState, - commitToHistory: false, + storeAction: "none", }); } for (const f of files) { @@ -1492,7 +1492,7 @@ export default class ExcalidrawView extends TextFileView { ...st, theme, }, - commitToHistory: false, + storeAction: "none", }); } @@ -2275,7 +2275,7 @@ export default class ExcalidrawView extends TextFileView { { elements: excalidrawData.elements.concat(deletedElements??[]), //need to preserve deleted elements during autosave if images, links, etc. are updated files: excalidrawData.files, - commitToHistory: true, + storeAction: "update", }, justloaded ); @@ -2288,7 +2288,7 @@ export default class ExcalidrawView extends TextFileView { ? this.excalidrawData.selectedElementIds : {}, zenModeEnabled, - viewModeEnabled: viewModeEnabled, + viewModeEnabled, linkOpacity: this.excalidrawData.getLinkOpacity(), trayModeEnabled: this.plugin.settings.defaultTrayMode, penMode: penEnabled, @@ -2298,10 +2298,7 @@ export default class ExcalidrawView extends TextFileView { pinnedScripts: this.plugin.settings.pinnedScripts, customPens: this.plugin.settings.customPens.slice(0,this.plugin.settings.numberOfCustomPens), }, - //files: excalidrawData.files, - //commitToHistory: true, }, - //justloaded, ); if ( this.app.workspace.getActiveViewOfType(ExcalidrawView) === this.leaf.view && @@ -2971,7 +2968,7 @@ export default class ExcalidrawView extends TextFileView { this.updateScene( { elements, - commitToHistory: true, + storeAction: "capture", }, shouldRestoreElements, ); @@ -5387,7 +5384,7 @@ export default class ExcalidrawView extends TextFileView { elements?: ExcalidrawElement[]; appState?: any; files?: any; - commitToHistory?: boolean; + storeAction?: "capture" | "none" | "update"; //https://github.com/excalidraw/excalidraw/pull/7898 }, shouldRestore: boolean = false, ) { diff --git a/src/dialogs/SuggesterInfo.ts b/src/dialogs/SuggesterInfo.ts index cdf6209..d15b7e5 100644 --- a/src/dialogs/SuggesterInfo.ts +++ b/src/dialogs/SuggesterInfo.ts @@ -686,8 +686,9 @@ export const EXCALIDRAW_AUTOMATE_INFO: SuggesterInfo[] = [ }, { field: "viewUpdateScene", - code: "viewUpdateScene(scene:{elements?:ExcalidrawElement[],appState?: AppState,files?: BinaryFileData,commitToHistory?: boolean,},restore:boolean=false):void", - desc: "Calls the ExcalidrawAPI updateScene function for the targetView. When restore=true, excalidraw will try to correct errors in the scene such as setting default values to missing element properties.", + code: "viewUpdateScene(scene:{elements?:ExcalidrawElement[],appState?: AppState,files?: BinaryFileData,commitToHistory?: boolean,storeAction?: 'capture' | 'none' | 'update'},restore:boolean=false):void", + desc: "Calls the ExcalidrawAPI updateScene function for the targetView. When restore=true, excalidraw will try to correct errors in the scene such as setting default values to missing element properties. " + + `Note that commitToHistory has been deprecated in Excalidraw and is no longer used. You should use storeAction instead. See ${hyperlink("https://github.com/excalidraw/excalidraw/pull/7898", "ExcalidrawAPI")} documentation for more information.`, after: "", }, {