diff --git a/src/vs/base/browser/ui/splitview/splitview.ts b/src/vs/base/browser/ui/splitview/splitview.ts index 979d0d9694b270ed06461e25d2aadf650c5be83a..9584ce7d4ae2bba1faf4a91a40d8a16c28343b50 100644 --- a/src/vs/base/browser/ui/splitview/splitview.ts +++ b/src/vs/base/browser/ui/splitview/splitview.ts @@ -505,30 +505,8 @@ export class SplitView extends Disposable { const minDeltaDown = downIndexes.length === 0 ? Number.NEGATIVE_INFINITY : downIndexes.reduce((r, i) => r + (sizes[i] - this.viewItems[i].viewMaximumSize), 0); const minDelta = Math.max(minDeltaUp, minDeltaDown); const maxDelta = Math.min(maxDeltaDown, maxDeltaUp); - - const findSnapIndex = (indexes: number[]): number | undefined => { - // visible views first - for (const index of indexes) { - if (!this.viewItems[index].visible) { - continue; - } - - if (this.viewItems[index].snap) { - return index; - } - } - - // then, hidden views - for (const index of indexes) { - if (!this.viewItems[index].visible && this.viewItems[index].snap) { - return index; - } - } - - return undefined; - }; - - const snapBeforeIndex = findSnapIndex(upIndexes); + const snapBeforeIndex = this.findFirstSnapIndex(upIndexes); + const snapAfterIndex = this.findFirstSnapIndex(downIndexes); if (typeof snapBeforeIndex === 'number') { const viewItem = this.viewItems[snapBeforeIndex]; @@ -540,8 +518,6 @@ export class SplitView extends Disposable { }; } - const snapAfterIndex = findSnapIndex(downIndexes); - if (typeof snapAfterIndex === 'number') { const viewItem = this.viewItems[snapAfterIndex]; const halfSize = Math.floor(viewItem.viewMinimumSize / 2); @@ -799,38 +775,31 @@ export class SplitView extends Disposable { previous = false; const expandsUp = reverseViews.map(i => previous = (i.maximumSize - i.size > 0) || previous).reverse(); - const firstVisibleViewIndex = firstIndex(this.viewItems, viewItem => viewItem.visible); + this.sashItems.forEach(({ sash }, index) => { + const min = !(collapsesDown[index] && expandsUp[index + 1]); + const max = !(expandsDown[index] && collapsesUp[index + 1]); - this.sashItems.forEach((s, i) => { - if (!this.viewItems[i].visible) { - if (i === firstVisibleViewIndex - 1) { - s.sash.state = SashState.Minimum; + if (min && max) { + const upIndexes = range(index, -1); + const downIndexes = range(index + 1, this.viewItems.length); + const snapBeforeIndex = this.findFirstSnapIndex(upIndexes); + const snapAfterIndex = this.findFirstSnapIndex(downIndexes); + + if (typeof snapBeforeIndex === 'number' && !this.viewItems[snapBeforeIndex].visible) { + sash.state = SashState.Minimum; + } else if (typeof snapAfterIndex === 'number' && !this.viewItems[snapAfterIndex].visible) { + sash.state = SashState.Maximum; } else { - s.sash.state = SashState.Disabled; + sash.state = SashState.Disabled; } + } else if (min && !max) { + sash.state = SashState.Minimum; + } else if (!min && max) { + sash.state = SashState.Maximum; } else { - const min = !(collapsesDown[i] && expandsUp[i + 1]); - const max = !(expandsDown[i] && collapsesUp[i + 1]); - - if (min && max) { - const before = !range(0, i + 1).some(i => !this.viewItems[i].snap || this.viewItems[i].visible); - const after = !range(i + 1, this.viewItems.length).some(i => !this.viewItems[i].snap || this.viewItems[i].visible); - - if (before) { - s.sash.state = SashState.Minimum; - } else if (after) { - s.sash.state = SashState.Maximum; - } else { - s.sash.state = SashState.Disabled; - } - } else if (min && !max) { - s.sash.state = SashState.Minimum; - } else if (!min && max) { - s.sash.state = SashState.Maximum; - } else { - s.sash.state = SashState.Enabled; - } + sash.state = SashState.Enabled; } + // } }); } @@ -848,6 +817,28 @@ export class SplitView extends Disposable { return 0; } + private findFirstSnapIndex(indexes: number[]): number | undefined { + // visible views first + for (const index of indexes) { + if (!this.viewItems[index].visible) { + continue; + } + + if (this.viewItems[index].snap) { + return index; + } + } + + // then, hidden views + for (const index of indexes) { + if (!this.viewItems[index].visible && this.viewItems[index].snap) { + return index; + } + } + + return undefined; + } + dispose(): void { super.dispose(); diff --git a/test/splitview/public/index.html b/test/splitview/public/index.html index 81bec11778fc826d821f2b95d093c2cb5b0c7b20..602682d6aab9233827291dc50e1a46472d325821 100644 --- a/test/splitview/public/index.html +++ b/test/splitview/public/index.html @@ -103,7 +103,7 @@ this.minimumSize = typeof minimumSize === 'number' ? minimumSize : 100; this.maximumSize = typeof maximumSize === 'number' ? maximumSize : Number.POSITIVE_INFINITY; this.onDidChange = Event.None; - this.snap = true; + this.snap = !minimumSize && !maximumSize; this.button = document.createElement('button'); this.button.onclick = () => splitview.setViewVisible(this.id, !splitview.isViewVisible(this.id));