Permalink
Browse files

Ignoring an hidden SVGLayer in the children getter

  • Loading branch information...
nvh committed Feb 12, 2018
1 parent 94daa97 commit 5ce33ab6254a5b76dcffe961cba631daf9d0bc49
Showing with 26 additions and 7 deletions.
  1. +11 −7 framer/Layer.coffee
  2. +15 −0 test/tests/LayerTest.coffee
View
@@ -704,8 +704,8 @@ class exports.Layer extends BaseClass
@frame = Utils.convertFrameFromContext(frame, @, false, false)
contentFrame: ->
return {x: 0, y: 0, width: 0, height: 0} unless @children.length
return Utils.frameMerge(_.map(@children, "frame"))
return {x: 0, y: 0, width: 0, height: 0} unless @_children.length
return Utils.frameMerge(_.map(@_children, "frame"))
totalFrame: ->
return Utils.frameMerge(@frame, @contentFrame())
@@ -994,7 +994,7 @@ class exports.Layer extends BaseClass
layer = @copySingle()
for child in @children
for child in @_children
copiedChild = child.copy()
copiedChild.parent = layer if copiedChild isnt null
@@ -1152,7 +1152,11 @@ class exports.Layer extends BaseClass
enumerable: false
exportable: false
importable: false
get: -> _.clone @_children
get: -> @_children.map (c) ->
if c instanceof SVGLayer and c.children.length is 1 and _.startsWith(c.name, '.')
return c.children[0]
else
return c
@define "siblings",
enumerable: false
@@ -1187,7 +1191,7 @@ class exports.Layer extends BaseClass
removeChild: (layer) ->
if layer not in @children
if layer not in @_children
return
layer.parent = null
@@ -1347,7 +1351,7 @@ class exports.Layer extends BaseClass
bringToFront: ->
maxIndex = null
siblings = @parent?.children ? @context._layers
siblings = @parent?._children ? @context._layers
return if siblings.count <= 1
for layer in siblings
continue if layer is @
@@ -1359,7 +1363,7 @@ class exports.Layer extends BaseClass
sendToBack: ->
minIndex = null
siblings = @parent?.children ? @context._layers
siblings = @parent?._children ? @context._layers
return if siblings.count <= 1
for layer in siblings
continue if layer is @
@@ -1120,6 +1120,21 @@ describe "Layer", ->
layerC.superLayer = null
assert.deepEqual layerA.children, []
it "should ignore a hidden SVGLayer", ->
layerA = new Layer
layerB = new Layer
parent: layerA
svgLayer = new SVGLayer
parent: layerA
name: ".SVGLayer"
svg: '<svg xmlns="http://www.w3.org/2000/svg" width="62" height="62"><path d="M 31 0 C 48.121 0 62 13.879 62 31 C 62 48.121 48.121 62 31 62 C 13.879 62 0 48.121 0 31 C 0 13.879 13.879 0 31 0 Z" name="Oval"></path></svg>'
svgLayer2 = new SVGLayer
parent: layerA
name: ".SVGLayer",
svg: '<svg xmlns="http://www.w3.org/2000/svg" width="62" height="62"><path d="M 31 0 L 40.111 18.46 L 60.483 21.42 L 45.741 35.79 L 49.221 56.08 L 31 46.5 L 12.779 56.08 L 16.259 35.79 L 1.517 21.42 L 21.889 18.46 Z" name="Star"></path></svg>'
layerA.children.length.should.equal 3
layerA.children.should.eql [layerB, svgLayer.children[0], svgLayer2.children[0]]
it "should list sibling root layers", ->
layerA = new Layer

0 comments on commit 5ce33ab

Please sign in to comment.