From 5ce33ab6254a5b76dcffe961cba631daf9d0bc49 Mon Sep 17 00:00:00 2001 From: Niels van Hoorn Date: Mon, 12 Feb 2018 13:20:46 +0100 Subject: [PATCH] Ignoring an hidden SVGLayer in the children getter --- framer/Layer.coffee | 18 +++++++++++------- test/tests/LayerTest.coffee | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/framer/Layer.coffee b/framer/Layer.coffee index 9a6d131b2..1063284b5 100644 --- a/framer/Layer.coffee +++ b/framer/Layer.coffee @@ -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 @ diff --git a/test/tests/LayerTest.coffee b/test/tests/LayerTest.coffee index 22604226a..b2e8b83f9 100644 --- a/test/tests/LayerTest.coffee +++ b/test/tests/LayerTest.coffee @@ -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: '' + svgLayer2 = new SVGLayer + parent: layerA + name: ".SVGLayer", + 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