Skip to content

Commit 514b51b

Browse files
committed
Fixes an issue that could cause Merge color variables to crash if there were Hotspots present in the document.
1 parent 845c469 commit 514b51b

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

merge-duplicates.sketchplugin/Contents/Sketch/Main.js

Lines changed: 19 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

merge-duplicates.sketchplugin/Contents/Sketch/Main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MergeColorVariables.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,29 @@ function doUseColorSwatchesInLayers(colorVariable, colorVariablesToRemove) {
6666
const map = new Map();
6767

6868
allLayers.forEach(layer => {
69-
if (layer.type != "Slice") {
70-
layer.style.fills
71-
.concat(layer.style.borders)
72-
.filter(item => item.fillType == 'Color')
73-
.forEach(item => {
69+
try{
70+
if ((layer.type != "Slice") && (layer.type != "HotSpot")) {
71+
layer.style.fills
72+
.concat(layer.style.borders)
73+
.filter(item => item.fillType == 'Color')
74+
.forEach(item => {
75+
colorVariablesToRemove.forEach(cvToRemove => {
76+
if (item.color == cvToRemove.color) {
77+
item.color = colorVariable.referencingColor;
78+
if (!map.has(layer)) map.set(layer, true);
79+
}
80+
});
81+
})
82+
// Previous actions don't work for Text Layer colors that are colored using TextColor, so let's fix that:
83+
if (layer.style.textColor) {
7484
colorVariablesToRemove.forEach(cvToRemove => {
75-
if (item.color == cvToRemove.color) {
76-
item.color = colorVariable.referencingColor;
77-
if (!map.has(layer)) map.set(layer, true);
78-
}
85+
if (layer.style.textColor == cvToRemove.color)
86+
layer.style.textColor = colorVariable.referencingColor;
7987
});
80-
})
81-
// Previous actions don't work for Text Layer colors that are colored using TextColor, so let's fix that:
82-
if (layer.style.textColor) {
83-
colorVariablesToRemove.forEach(cvToRemove => {
84-
if (layer.style.textColor == cvToRemove.color)
85-
layer.style.textColor = colorVariable.referencingColor;
86-
});
88+
}
8789
}
90+
}catch (e){
91+
console.log("Accessing style for layer '"+layer.name+"' ("+layer.type+") failed, and couldn't be checked.");
8892
}
8993
});
9094

0 commit comments

Comments
 (0)