Skip to main content

Hello,

I’m researching possibilities for our plugin.


Our use case:



  • we store some plugin data using Figma’s getPluginData() - we arbitrarily tie the stored data to node.id provided by Figma

  • on node copy+paste / duplicate, we would like to trigger a callback to check the original node, copy its plugin data and store it also for the node.id that has been created by the duplication / paste operation


From what I researched so far, there is no way to hook on paste / duplicate events (also because the callback would only be executed if the user performs such actions with our plugin open). But nevertheless I’d like to ask here, maybe someone could point me in the right direction?


Thank you, best regards,

Ondřej Frei

An alternative idea to achieve this: Can we somehow hook into node instantiation? In that moment, we could compare the just-created node with the existing ones and thus detect if it has been copied / duplicated.


If there is such way, does the plugin need to be open for it to work? Meaning that if the user does not open the plugin, there would be no chance to monitor newly created nodes like this?


You can store node.id directly in the plugin data, and the next time you open the plugin, simply check if the current node.id is equal to the saved one. If not, you can do your stuff.


Thank you @tonypinkevych! Let me make sure I understand you correctly - the node id can change over time, or you mean a situation that it’s in fact a different node?


No it won’t change overtime automatically 🙂

According to my observations it changes only when you make copy/paste or duplication within the same Figma file. But if you copy-paste from one file to another it will keep the same id.


@tonypinkevych thank you for this insight! So on opening the plugin, you’d suggest to go through all the nodes and check if they have previously been saved into the plugin data? And if not, it means they’re new and possibly copied?



  1. When your plugin do something with node → you store node id with setPluginData;

  2. Next time when your plugin want to do something with this node you can compare node.id === node.getPluginData().storedId. And if they are not equal do something with this.


Thank you for your help @tonypinkevych 🚀


Reply