Skip to content

Commit 6d6ba0a

Browse files
committed
1.0.12 - support sketch 48 overrides
1 parent e0a6e64 commit 6d6ba0a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

library-symbol-replacer.sketchplugin/Contents/Sketch/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Library Symbol Replacer",
33
"identifier": "com.zeroheight.library-symbol-replacer",
4-
"version": "1.0.11",
4+
"version": "1.0.12",
55
"description": "replace local symbols with library symbols",
66
"authorEmail": "[email protected]",
77
"author": "zeroheight team",

library-symbol-replacer.sketchplugin/Contents/Sketch/script.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var replaceFromUrl = function(context,url){
8181
return;
8282
}
8383

84+
// first pass imports foreign symbols and builds the idmap
8485
var idmap = {};
8586
for(var i = 0 ; i < imports.length ; ++i){
8687
var obj = imports[i];
@@ -92,17 +93,29 @@ var replaceFromUrl = function(context,url){
9293
var localID = String(obj.localSymbol.symbolID());
9394
var foreignID = String(importedSymbol.symbolMaster().symbolID());
9495
idmap[localID] = foreignID;
96+
}
9597

96-
// replace all local instances with the newly imported symbol
98+
for(var i = 0 ; i < imports.length ; ++i){
99+
var obj = imports[i];
100+
// replace all local instances with the newly imported symbol, taking care to update
101+
// the overrides first
97102
for(var j = 0 ; j < obj.localInstances.length ; ++j){
98-
obj.localInstances[j].changeInstanceToSymbol(importedSymbol.symbolMaster());
103+
if(!MSLayerPaster.updateOverridesOnInstance_withIDMap_){
104+
obj.localInstances[j].updateOverridesWithObjectIDMap(idmap);
105+
}else{
106+
MSLayerPaster.updateOverridesOnInstance_withIDMap_(obj.localInstances[j], idmap);
107+
}
99108
}
100109
}
101110

102-
// ensure there are no dangling overrides still pointing to local symbols
111+
// finally, ensure there are no dangling overrides in instances we haven't replaced
103112
var allInstances = getAllInstances(context.document);
104113
for(var i = 0 ; i < allInstances.length ; ++i){
105-
MSLayerPaster.updateOverridesOnInstance_withIDMap_(allInstances[i], idmap);
114+
if(!MSLayerPaster.updateOverridesOnInstance_withIDMap_){
115+
allInstances[i].updateOverridesWithObjectIDMap(idmap);
116+
}else{
117+
MSLayerPaster.updateOverridesOnInstance_withIDMap_(allInstances[i], idmap);
118+
}
106119
}
107120

108121
var decision = yesNoDialog('Cool! All done.\n\nDo you want to delete the ' +

0 commit comments

Comments
 (0)