I am experimenting with onDocumentChange to create a plugin to allow for aligning and ordering instances of a specific symbol. For example, after moving, deleting or inserting instances of one symbol the plugin organizes and aligns them on the artboard, similar to 'Clean up' on MacOS Finder.
However I have realized that Undo (cmd+z) is effectively "disabled" in some situations. For example, I delete a layer in my document (change detected) and the plugin repositions surrounding layers to account for the change. Then I decide that was a mistake and I Undo (change detected). At this point, Undo reverts the position changes the plugin just made. But this itself is a document change, which triggers onDocumentChange again and the plugin again repositions surrounding layers. In effect, the document is caught in a loop such that I can never Undo the layer deletion.
Perhaps I'm implementing onDocumentChange poorly? Or is this a use case that was not anticipated? What kind of actions was onDocumentChange intended for? Is there a way to detect Undo and exempt that from onDocumentChange -- or perhaps something more graceful?
Thanks in advance!