From f6b20cd31c06119bb58708b37d5a9dc3c4e9ed05 Mon Sep 17 00:00:00 2001 From: Matthew Dapena-Tretter Date: Fri, 14 Apr 2017 15:14:28 -0700 Subject: [PATCH] Reduce dock initial size lookups Previously, we would get the initial size every time we didn't have an explicit one. With this commit, we only get the initial size when we deserialize and when we go from 0 -> 1 pane items. Also, if the dock doesn't already have an explicit size, we'll use the preferred size of the item being dragged when peaking the dock. That way, dropping it won't cause it to change size. --- src/dock.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/dock.js b/src/dock.js index f6a7aa0e4..91754e9be 100644 --- a/src/dock.js +++ b/src/dock.js @@ -56,6 +56,7 @@ module.exports = class Dock { this.didActivate(this) }), this.paneContainer.observePanes(pane => { + pane.onDidAddItem(this.handleDidAddPaneItem.bind(this)) pane.onDidRemoveItem(this.handleDidRemovePaneItem.bind(this)) }), this.paneContainer.onDidChangeActivePane((item) => params.didChangeActivePane(this, item)), @@ -206,7 +207,11 @@ module.exports = class Dock { } const shouldBeVisible = state.visible || state.showDropTarget - const size = Math.max(MINIMUM_SIZE, state.size == null ? this.getInitialSize() : state.size) + const size = Math.max(MINIMUM_SIZE, + state.size || + (state.draggingItem && getPreferredSize(state.draggingItem, this.location)) || + DEFAULT_INITIAL_SIZE + ) // We need to change the size of the mask... this.maskElement.style[this.widthOrHeight] = `${shouldBeVisible ? size : 0}px` @@ -224,10 +229,16 @@ module.exports = class Dock { }) } + handleDidAddPaneItem () { + if (this.state.size == null) { + this.setState({size: this.getInitialSize()}) + } + } + handleDidRemovePaneItem () { // Hide the dock if you remove the last item. if (this.paneContainer.getPaneItems().length === 0) { - this.setState({visible: false, hovered: false}) + this.setState({visible: false, hovered: false, size: null}) } } @@ -340,13 +351,12 @@ module.exports = class Dock { } getInitialSize () { - let initialSize // The item may not have been activated yet. If that's the case, just use the first item. const activePaneItem = this.paneContainer.getActivePaneItem() || this.paneContainer.getPaneItems()[0] - if (activePaneItem != null) { - initialSize = getPreferredSize(activePaneItem, this.location) - } - return initialSize == null ? DEFAULT_INITIAL_SIZE : initialSize + // If there are items, we should have an explicit width; if not, we shouldn't. + return activePaneItem + ? getPreferredSize(activePaneItem, this.location) || DEFAULT_INITIAL_SIZE + : null } serialize () { @@ -361,7 +371,7 @@ module.exports = class Dock { deserialize (serialized, deserializerManager) { this.paneContainer.deserialize(serialized.paneContainer, deserializerManager) this.setState({ - size: serialized.size, + size: serialized.size || this.getInitialSize(), // If no items could be deserialized, we don't want to show the dock (even if it was visible last time) visible: serialized.visible && (this.paneContainer.getPaneItems().length > 0) })