sonburn/symbol-instance-locator

Search overrides

d4rekanguok opened this issue ยท 8 comments

Hey Jason, awesome plugin! This is actually exactly what I'm working toward to with my Instance locator plugin.

I'm actually working on one extra feature, that is searching for instance that is nested / overridden in a parent symbol. Do you have plans for this? Otherwise I'd love to retire mine, since yours is better.

@d4rekanguok Yes, I do plan to add overrides, just haven't gotten around to it yet. I already have the functionality in Symbol Organizer, just need to port it over to Instance Locator.

@d4rekanguok I have added this functionality to v1.5. Give it a whirl!

@sonburn Sweet, I struggled with this feature so can't wait to see how you handle it!

It was definitely complicated, in part because old overrides don't get removed when symbols change/swap over time, so you can have orphaned references to your currently selected symbol which you need to filter out.

For example... here are the overrides for a list item with text and icons which can be overridden.

{
"19E10E5A-AC44-436E-A0C7-12118E0C2C6F" = Photos;
"3346BCEE-0943-400E-AA68-F27359689ADB" = {
symbolID = "8C89DA8E-ACDB-4350-8DAB-4ABF7B44AAB1";
};
"9228C6F1-8B20-44EC-992C-9E1934ADFEF4" = {
symbolID = "CB326880-1752-4583-BDD5-1D12467702C6";
};
"DBBE3357-792A-49F2-93E7-367FFC035EC8" = {
symbolID = "CB326880-1752-4583-BDD5-1D12467702C6";
};
"F7A74DEB-4B78-4B68-98A8-F6CF6B62F55A" = {
symbolID = "CB326880-1752-4583-BDD5-1D12467702C6";
};
}

Note how "CB326880-1752-4583-BDD5-1D12467702C6" appears three times, but in actuality only one of those ancestor IDs are active in the symbol. The other two are old IDs which are no longer present in the symbol. If the old symbol with the old ID was ever added back to the symbol, the override would appear again as the information is still present. But because the old override reference is present in the symbol, I have to filter the overrides to only show instances where the selected symbol is actually in use.

In order to filter it, you have to figure out what are the valid active IDs in the master symbol, and that was the tricky part to figure out as the overrides object isn't available in a symbol instance until you actually override something. After doing some research into the headers, I found availableOverrides() and overridePoints() on MSSymbolInstance. The former seemed promising but was a dead end, but the latter exposes the ancestor IDs, so I was able to make that work.

Hope all that makes sense, might be useful information if you ever do anything with overrides.

Exactly, i found it so confusing that overrides don't get removed. overridePoints() looks interesting, thanks for the awesome tip!

@sonburn I've just gave the new version a test:
test sketch file

Set up
Create the following:

  • symbol A and symbol A', both can replace each other when nested inside other symbols
  • symbol B that contains symbol A
  • symbol B' that contains symbol A'
  • symbol C that contains symbol B

Before running plugin

  • Put one instance of symbol A', symbol B, symbol B' and symbol C on an artboard
  • In symbol B's instance, swap symbol A with A'
  • In symbol C's instance, swap symbol A with A'
  • Select an instance of symbol A'

Result after running the plugin on instance of symbol A'

  • Instance of symbol B is listed -- plugin successfully detect symbol A' override in symbol B
  • Instance of symbol C is not listed, even though it contains symbol A' -- Override that is nested more than 1 level deep is not detected
  • Instance of symbol B' is not listed, even though it contains symbol A' -- Nested symbol that was not overridden is not detected

The plugin runs well and the search result is enough to be already super useful to users, I think it will be even more perfect to include instances of nested symbol that wasn't overridden and instances of nested symbol deeper than 1 levels!

Including instances of nested symbol wasn't a problem for me, but I was trying to write a recursive search in override tree of each instance to detect deep level nesting and struggle with that ๐Ÿ˜“ What do you think of the problem?

I just published an update (1.11) which should do a better job of finding instances of a symbol used as overrides. Let me know if you have a better experience.

Wow, thank you for keeping at it. I'll check it out!