Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: undo/history not properly initialized #1791

Closed
dwelle opened this issue May 22, 2024 · 6 comments
Closed

BUG: undo/history not properly initialized #1791

dwelle opened this issue May 22, 2024 · 6 comments

Comments

@dwelle
Copy link

dwelle commented May 22, 2024

Your environment
SYSTEM INFO:
Obsidian version: v1.5.12
Installer version: v1.5.12
Operating system: Windows 10 Pro 10.0.19045
Login status: not logged in
Insider build toggle: off
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 1
Plugins enabled: 1
1: Excalidraw v2.2.2

Describe the bug

History is not initialized properly. Undo on initial load of a file removes all content. Even after first change is made after load, first undo removes all content.

@zsviczian if you can point to where you initialize/update data, I can take a look.

@zsviczian
Copy link
Owner

Ok. I can reproduce.
Based on my quick testing this only seems to happen when you load another drawing into an already open Excalidraw tab. The issue likely stems from that I reset the Scene, not reload Excalidraw when you change files. I call resetScene() on the Excalidraw API.

clear() {
this.canvasNodeFactory.purgeNodes();
this.embeddableRefs.clear();
this.embeddableLeafRefs.clear();
delete this.exportDialog;
const api = this.excalidrawAPI;
if (!api) {
return;
}
if (this.activeLoader) {
this.activeLoader.terminate = true;
this.activeLoader = null;
}
this.nextLoader = null;
api.resetScene();
this.previousSceneVersion = 0;
}

@dwelle
Copy link
Author

dwelle commented May 22, 2024

resetScene() also clears history, so it's not the whole story. Where you do populate the scene with the new file contents?

@zsviczian
Copy link
Owner

I simply call updateScene(). I do it in two steps, first to load the elements, then a successive updateScene to set appState.

this.updateScene(
{
elements: excalidrawData.elements.concat(deletedElements??[]), //need to preserve deleted elements during autosave if images, links, etc. are updated
files: excalidrawData.files,
commitToHistory: true,
},
justloaded
);
this.updateScene(
{
//elements: excalidrawData.elements.concat(deletedElements??[]), //need to preserve deleted elements during autosave if images, links, etc. are updated
appState: {
...excalidrawData.appState,
...this.excalidrawData.selectedElementIds //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/609
? this.excalidrawData.selectedElementIds
: {},
zenModeEnabled,
viewModeEnabled: viewModeEnabled,
linkOpacity: this.excalidrawData.getLinkOpacity(),
trayModeEnabled: this.plugin.settings.defaultTrayMode,
penMode: penEnabled,
penDetected: penEnabled,
allowPinchZoom: this.plugin.settings.allowPinchZoom,
allowWheelZoom: this.plugin.settings.allowWheelZoom,
pinnedScripts: this.plugin.settings.pinnedScripts,
customPens: this.plugin.settings.customPens.slice(0,this.plugin.settings.numberOfCustomPens),
},
//files: excalidrawData.files,
//commitToHistory: true,
},
//justloaded,
);

@dwelle
Copy link
Author

dwelle commented May 22, 2024

Ah. The new history API has changed the commitToHistory attribute of updateScene to storeAction.

You'll want to update commitToHistory: true to storeAction: "capture".

(I've also noticed we have incorrect tsdoc saying the default is capture, but it is none to align with previous behavior).

(see breaking changes in our changelog)

@zsviczian
Copy link
Owner

Thanks! I notice this is an issue in a number of my scripts as well. I will clean this up for the next release.

@zsviczian
Copy link
Owner

...and I need storeAction: "update" at the time of the initial load.
Done, working, will release in 2.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants