Skip to main content
Question

Listening for changes using figma.on()


aamir.shaikh

I want to change my plugin UI when the selection changes in the editor.

This is the code I am using to listen for changes in my code.ts file:

figma.on("selectionchange", () => {
  figma.ui.postMessage(selectedTextNodes.length)
})

And this is the code I’m using to receive the changes in ui.html:

onmessage = (event) => {
    document.getElementById('layers-selected').innerHTML = `${event.data.pluginMessage} text layer${event.data.pluginMessage === 1 ? '':'s'} selected`
  }

However, this isn’t working. Am I using a wrong approach? If so, what would be the right one?

This topic has been closed for replies.

2 replies

tank666
  • 4873 replies
  • April 17, 2023

The code snippets shown work as expected. Check the code you didn’t share.


aamir.shaikh

Thanks. The bug was that I was sending the variable v=value, which was declared when the plugin first ran.

Instead, I should be sending real time ‘value’, and not the previously defined variable.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings