Skip to main content
aamir.shaikh
April 14, 2023
Question

Does anybody have an example of successful implementation of setRangeFills()?

  • April 14, 2023
  • 11 replies
  • 609 views

I’m trying this format but it’s not working
text.setRangeFills(start, end, object.fills)

This topic has been closed for replies.

11 replies

tank666
April 14, 2023

It must be an array of objects.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
aamir.shaikh
April 14, 2023

Yes it is, but it still doesn’t work. Here’s object.fills:

[
    {
        "type": "SOLID",
        "visible": true,
        "opacity": 1,
        "blendMode": "NORMAL",
        "color": {
            "r": 0.9416666626930237,
            "g": 0,
            "b": 3.367662486652989e-7
        }
    }
]
tank666
April 14, 2023

What error do you see in the console?

figma.com
UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
aamir.shaikh
April 14, 2023

I don’t see any error.

I am trying to get and set fills for a text node.
The reference text is “hello”, where “he” is white and “llo” is red.
When I apply the fills to the output, it is all white and not according to the reference text.

aamir.shaikh
April 14, 2023

image
it is between 0 and 1

tank666
April 14, 2023

How many times do you call the setRangeFills method?

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
aamir.shaikh
April 14, 2023

20 times in the above case (string.length * 4)

tank666
April 14, 2023

Sorry, but you are doing something wrong. You only need to call this method 2 times. The first time to set the fill to white, the second time to set it to red.

text.setRangeFills(0, 2, [whiteFill]);
text.setRangeFills(3, 5, [redFill]);
UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
aamir.shaikh
April 14, 2023

Sorry for the confusion.

I am calling it 2 times per Text Node. I have 2 text nodes for each letter in the string.
So, 2 x 2 x 5 = 20

tank666
April 14, 2023

At the moment, I can only suggest that you revise your code that was left behind the scenes. Or share enough code so that anyone can reproduce what you’re experiencing.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank