yuleicul / obsidian-ketcher

View or draw chemical structures and reactions using Ketcher.
https://obsidian.md/plugins?search=yulei%20chen
Apache License 2.0
32 stars 2 forks source link

`undo` just reverts what `setMolecule` did #12

Open yuleicul opened 1 year ago

yuleicul commented 1 year ago

This is also related to the boundary case, that multiple tabs sharing the same file. In this case, when one tab calls save(), the _check flag in setViewData() of other tabs will be false. So through wrapping render KetcherReact, we can retain the editor, and just refresh the data.

With this specific case I found another problem. If we assign the view data through ketcher.setMolecule(), and the undo operation would just revert what the funcion did.

When we have two tabs, drawing on Tab A and updating Tab B automatically, the undo stack of Tab B behaves weird. For obsidian-ketcher v0.1.2, after refreshing the editor, undo will leave a blank canvas on Tab B, because we re-render the editor, and then assign the data value to the tab. For the proposed change, undo will revert save() operation, and we will get the previous state since we retained the editor and pervious data.

If there's a way to interact with the undo stack of ketcher editor, we can even keep it on the page (init in the constructor of KetView), and just update the data. (Update: code here https://github.com/Acylation/obsidian-ketcher/tree/single-editor-instance)

Originally posted by @Acylation in https://github.com/yuleicul/obsidian-ketcher/issues/10#issuecomment-1674451019