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

DocumentSaved.Begin action? #552

Open
jwdallas opened this issue Jun 18, 2019 · 1 comment
Open

DocumentSaved.Begin action? #552

jwdallas opened this issue Jun 18, 2019 · 1 comment

Comments

@jwdallas
Copy link
Contributor

Is there any way to run a plugin just before the document is saved? I was really hoping for a 'DocumentSaved.Begin' action to exist, but that doesn't seem to be the case. Or maybe it's named something else?? 😅 ('DocumentSaved.Begin' doesn't make much grammatical sense).

Some context, I'm working on a plugin that changes improves some formatting of the document when it is saved. This seems like a pretty standard thing to do, most modern code editors now can autoformat code on save. However, the DocumentSaved action only seems to run the plugin after the save has happened which means any modifications that the plugin makes are not saved and the document is left in an 'unsaved changes' state immediately after saving.

Working around this currently by writing a bunch of code to diff my changes to document against what is currently in the document and then not doing anything if it won't change anything. This allows the plugin to call document save again after it is finished so that from the user’s perspective it doesn't look like anything wonky is going on. The diffing code is very complex relative to the rest of the plugin and would love not to need to maintain it going forward.

(😃 A million thanks for creating such an awesome product and supremely intuitive API. I wasn't expecting to be able to achieve a plugin with even a quarter of the functionality my plugin now has, it's incredible. The documentation and API are overall some of the best I've ever seen/used. 'Actions' seems to be a rough patch at the moment, but I'm sure that'll get improved! The functionality added there is completely brilliant.)

@christianklotz
Copy link
Contributor

Thank you for your feedback 🙏 We currently working on improved Sketch lifecycle APIs as well as providing better ways to handle document changes, also see https://sketchplugins.com/d/1390-feedback-wanted-new-events-api/3.

Both will hopefully help make your life easier developing your plugin.

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