Skip to main content
Akshat_Sharma1
Oct 13, 2023 3:03 AM UTC
Question

SelectionChange not firing

I was designing a plugin, where one could click on a selected object and show all its properties onto the same figure. I want to dynamically change selection once user clicks any other shape but i have problem figuring out why my Figma.on not working.

Here is the code:

function runplugin() {
  let selectedElements = figma.currentPage.selection;

  if (selectedElements.length === 0) {
    figma.closePlugin('No elements selected');
    return;
  }

  if (selectedElements.length > 1) {
    figma.closePlugin('Please select one element');
    return;
  }

 console.log('hello');
}

figma.on('selectionchange', () => {
  console.log(figma.currentPage.selection);
  console.log('j');
});



figma.closePlugin()

Code is changed to debug. Please Help

This topic has been closed for replies.

1 reply

tank666
Oct 13, 2023 10:56 AM UTC

Firstly: the runplugin function is not called anywhere in your code.
Secondly: the plugin closes immediately after launch due to the last line.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank