Should I be listening for a drop event in figma.on? I’ve seen a forum post about drag and dropping here but it seems to pertain only to dropping from files outside of Figma ie dragging from the plugin iframe
(I’m calling the resize() function in my resizeToAspect())
Problem is, every time I call resize() while the node is being resized via Figma’s transform controls, it also fires another documentChange event which leads to a weird flickering effect. That’s why I only want to call my custom function after the user has released their mouse after dragging the width/height of a node in Figma.
Is there a way for me to detect the end of a drag event in Figma using documentChange?
in that case, is it possible to detect if the user has moused up in the Figma file? I know that the plugin UI aka ui.html can listen for mouse events, but can that be done from the Figma file itself eg figma.
Nope, there is no way to listen for canvas interactions in any way.
One thing you can do is debounce the resize action. E.g. if the user hasn’t changed the size of an object in 3-5 seconds, it’s relatively safe to assume they stopped resizing it, so the plugin can do its thing. You can experiment with different timings for the best possible experience.
Thanks, I tried to use debounce from JQuery and some TS-version of it from NPM but I couldn’t figure out how to get it to work. So for now, I just implemented a barebones version of it like so: