Skip to content

Commit

Permalink
Ignoring an hidden SVGLayer in the children getter
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Feb 12, 2018
1 parent 94daa97 commit 5ce33ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
18 changes: 11 additions & 7 deletions framer/Layer.coffee
Expand Up @@ -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())
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 @
Expand All @@ -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 @
Expand Down
15 changes: 15 additions & 0 deletions test/tests/LayerTest.coffee
Expand Up @@ -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
Expand Down

0 comments on commit 5ce33ab

Please sign in to comment.