Skip to main content
Question

Const node of figma.currentPage.selection ordered by layer heirarchy


Nathan_Blaylock

I am developing a plugin to insert text into each selected text node. It is working well, except that it is inserting each text item ordered by when the node was created. I have moved around the text nodes in the layers panel hoping that the order of the layer would impact the insertion order, but that didn’t change anything. Here is what I have:

figma.ui.onmessage = async (msg) => {
  if (msg.type === 'add-date') {
    for (const node of figma.currentPage.selection) {
      if (node.type == 'TEXT') {
        const fonts = node.getRangeAllFontNames(0, node.characters.length);
        for (const font of fonts) {
          await figma.loadFontAsync(font);
        }
        node.characters = msg.dates.shift();
      }
    }
  }
  figma.closePlugin();
};

On that third line down, how do I tell it to get the node in order by layer hierarchy, not creation time?

Thanks in advance.

0 replies

Be the first to reply!

Reply


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