Skip to main content
Question

Try to create List


Nikita34

Hello there

I am trying to create a plugin to generate a list. I use the setRangeListOptions() function.

figma.ui.onmessage = async (mesg) => {
  await figma.loadFontAsync({ family: "Inter", style: "Regular" })
      var text = figma.createText()
          type TextListOptions = { type: "UNORDERED"};
          text.setRangeListOptions(1, 2,  globalThis.TextListOptions)
      figma.closePlugin()

}

I’m creating a text node, but I can’t put a nested list in it.
At the same time, he writes that “TextListOptions” is declared, but has never been used.
And a warning:

4 replies

Gleb
  • Power Member
  • 4708 replies
  • May 4, 2022

You don’t have any text in the text field so there is no range to set the list to. Set text.characters="blablabla", then you can add a list to the existing text.

You picked the range from character at index 1 to index 2 (only character at index 1, the second in the characters string, will be in this range) and the warning tells you the range you picked is outside of the current character string length (which is 0, since you didn’t set any text on it).


Nikita34
  • Author
  • 4 replies
  • May 4, 2022

Okay, I added the text
But the list does not appear, writes that the TextListOption is not used. How should I write it in the getRangeListOption() function?

figma.ui.onmessage = async (mesg) => {
  await figma.loadFontAsync({ family: "Inter", style: "Regular" })
      var text = figma.createText()
          type TextListOptions = { type: "UNORDERED"};
          text.characters = "blabla"
          text.setRangeListOptions(1, 10,  globalThis.TextListOptions)
      figma.closePlugin()
}

Gleb
  • Power Member
  • 4708 replies
  • May 4, 2022

Firstly, why are you using a type instead of a variable? What is globalThis? Also again you set the range outside of the length of the string. blabla is only 6 characters long but you are trying to make a range from 2nd to 10th character.

The following might work:

text.characters = "blabla"
text.setRangeListOptions(1, 5, { type: "UNORDERED"})

Nikita34
  • Author
  • 4 replies
  • May 4, 2022

Oh, thank you, Gleb
I just started to figure it out, thanks for the indicated errors.


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