Skip to content

Commit

Permalink
Fixes an issue that could cause Merge color variables to crash if the…
Browse files Browse the repository at this point in the history
…re were Hotspots present in the document.
  • Loading branch information
oodesign committed Jan 19, 2022
1 parent 845c469 commit 514b51b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
34 changes: 19 additions & 15 deletions merge-duplicates.sketchplugin/Contents/Sketch/Main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion merge-duplicates.sketchplugin/Contents/Sketch/Main.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions src/MergeColorVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,29 @@ function doUseColorSwatchesInLayers(colorVariable, colorVariablesToRemove) {
const map = new Map();

allLayers.forEach(layer => {
if (layer.type != "Slice") {
layer.style.fills
.concat(layer.style.borders)
.filter(item => item.fillType == 'Color')
.forEach(item => {
try{
if ((layer.type != "Slice") && (layer.type != "HotSpot")) {
layer.style.fills
.concat(layer.style.borders)
.filter(item => item.fillType == 'Color')
.forEach(item => {
colorVariablesToRemove.forEach(cvToRemove => {
if (item.color == cvToRemove.color) {
item.color = colorVariable.referencingColor;
if (!map.has(layer)) map.set(layer, true);
}
});
})
// Previous actions don't work for Text Layer colors that are colored using TextColor, so let's fix that:
if (layer.style.textColor) {
colorVariablesToRemove.forEach(cvToRemove => {
if (item.color == cvToRemove.color) {
item.color = colorVariable.referencingColor;
if (!map.has(layer)) map.set(layer, true);
}
if (layer.style.textColor == cvToRemove.color)
layer.style.textColor = colorVariable.referencingColor;
});
})
// Previous actions don't work for Text Layer colors that are colored using TextColor, so let's fix that:
if (layer.style.textColor) {
colorVariablesToRemove.forEach(cvToRemove => {
if (layer.style.textColor == cvToRemove.color)
layer.style.textColor = colorVariable.referencingColor;
});
}
}
}catch (e){
console.log("Accessing style for layer '"+layer.name+"' ("+layer.type+") failed, and couldn't be checked.");
}
});

Expand Down

0 comments on commit 514b51b

Please sign in to comment.