DWilliames / paddy-sketch-plugin

Automated padding, spacing and alignment for your Sketch layers
MIT License
2.17k stars 61 forks source link

Update shouldLayerBeIgnored() #66 #77

Closed d4rekanguok closed 6 years ago

d4rekanguok commented 6 years ago

Hey D, my proposal for #66 :

Sketch names text layers to its content & update automatically unless the layer's name is manually modified. Therefore we can safely assume that if a text layer's value matches its name, it's unmodified and shouldn't be ignored.

DWilliames commented 6 years ago

Thanks @d4rekanguok. Only just getting around to this now. Great solution!!

I'll merge this into the v1.0.7 branch rather than Master for now. Will hopefully release it soon.

DWilliames commented 6 years ago

@d4rekanguok just an FYI I actually updated it slightly to be...

// If the layer should be ignored when calculating the rect of a layer
function shouldLayerBeIgnored(layer) {
  if (!layer) return

  if (layer.name().startsWith('-')) {

    // Don't ignore if layer is a text layer whose name wasn't manually modified
    if (layer.isMemberOfClass(MSTextLayer) && layer.stringValue() == layer.name()) {
      return false
    }

    return true
  }

  return false
}

I think putting it within the layer.name().startsWith('-') condition will be more performant. Because this function is called quite a lot, it means it will only check if the name matches the value if we already know the first character is '-' — as opposed to checking if the value is the same as name every single time.

Great work by the way! 👍

d4rekanguok commented 6 years ago

Thanks @DWilliames, moving the condition inside the startwith block makes sense. Thanks for the great plugin!