Figma Support Forum

Unable to swap text style

I have a design file that contains a reference to a text style in a deprecated library. Or so does the Library dialog indicate. Otherwise, that reference is nowhere to be found in the file. The Swap Library function would be ideal here, but somehow it doesn’t work for me because it won’t match the style name in a newer library, despite the path and name being identical (except maybe for spaces around the path delimiters?). Any ideas why that fails?

I searched for the reference as deep as I possibly could (it is admittedly a large file), including using the Similayer plugin, and the plugin API, to no avail. Here is the code I tried:

figma.currentPage.selection =
  figma.currentPage.findAll(n => n.type === "TEXT")
    .filter(n => !!n.textStyleId &&
      n.textStyleId !== figma.mixed &&
      figma.getStyleById(n.textStyleId)?.name === "Paragraph/Desktop/default")

Granted, this code could miss cases where the style is used only on a range of text within the text element, but the TextNode.getRangeTextStyleId method returns a single string or figma.mixed, so to locate a given style, one would have to test all the possible ranges in the TextNode. That’s impractical. Isn’t there a method to enumerate ranges with distinct styles within a TextNode?

Also, using the TextStyle object obtained from a variation on the above code, I couldn’t figure out how to determine what library the style comes from. That is a problem because as previously mentioned, I have styles with the same name in an old deprecated library and in a newer library, and both are used in the current design file. I can tell the difference manually in the UI, but that is yet another stumbling block on my way to an efficient solution.

Any ideas about what else I could try to get out of this?