Skip to main content
Question

Listening for changes using figma.on()

  • April 17, 2023
  • 2 replies
  • 967 views

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
  • 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.