diff --git a/src/pane-axis.coffee b/src/pane-axis.coffee index 3df39c683..9d946b391 100644 --- a/src/pane-axis.coffee +++ b/src/pane-axis.coffee @@ -83,6 +83,16 @@ class PaneAxis extends Model @children.splice(index, 0, child) @emitter.emit 'did-add-child', {child, index} + adjustFlexScale: -> + # get current total flex scale of children + total = 0 + total += child.getFlexScale() for child in @children + + needTotal = @children.length + # set every child's flex scale by the ratio + for child in @children + child.setFlexScale(needTotal * child.getFlexScale() / total) + removeChild: (child, replacing=false) -> index = @children.indexOf(child) throw new Error("Removing non-existent child") if index is -1 @@ -90,6 +100,7 @@ class PaneAxis extends Model @unsubscribeFromChild(child) @children.splice(index, 1) + @adjustFlexScale() @emitter.emit 'did-remove-child', {child, index} @reparentLastChild() if not replacing and @children.length < 2 @@ -113,7 +124,9 @@ class PaneAxis extends Model @addChild(newChild, index + 1) reparentLastChild: -> - @parent.replaceChild(this, @children[0]) + lastChild = @children[0] + lastChild.setFlexScale(@flexScale) + @parent.replaceChild(this, lastChild) @destroy() subscribeToChild: (child) -> diff --git a/src/pane-resize-handle-element.coffee b/src/pane-resize-handle-element.coffee index aca900d99..74b2a1989 100644 --- a/src/pane-resize-handle-element.coffee +++ b/src/pane-resize-handle-element.coffee @@ -13,8 +13,8 @@ class PaneResizeHandleElement extends HTMLElement resizeToFitContent: -> # clear flex-grow css style of both pane - @previousSibling.style.flexGrow = '' - @nextSibling.style.flexGrow = '' + @previousSibling.model.setFlexScale(1) + @nextSibling.model.setFlexScale(1) resizeStarted: (e)-> e.stopPropagation() @@ -30,8 +30,8 @@ class PaneResizeHandleElement extends HTMLElement [total * ratio1 / allRatio, total * ratio2 / allRatio] setFlexGrow: (prevSize, nextSize) -> - @prevModel = @previousSibling.getModel() - @nextModel = @nextSibling.getModel() + @prevModel = @previousSibling.model + @nextModel = @nextSibling.model totalScale = @prevModel.getFlexScale() + @nextModel.getFlexScale() flexGrows = @calcRatio(prevSize, nextSize, totalScale) @prevModel.setFlexScale flexGrows[0]