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?