Skip to content

Commit 3e96ff7

Browse files
committed
Merge pull request #334864 from microsoft/mrleemurray/fix-sidebar-width-reset-on-toggle
Fix primary side bar width reset when toggled with the side bar on the right
1 parent df7852a commit 3e96ff7

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/vs/base/browser/ui/splitview/splitview.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,13 @@ export class SplitView<TLayoutContext = undefined, TView extends IView<TLayoutCo
10171017
this.layoutViews();
10181018
} else {
10191019
item.size = size;
1020-
this.relayout([index], undefined);
1020+
1021+
// Absorb the change by layout priority, like `resizeView` does, so a neighbour with a size of its own is not squeezed (see #334167)
1022+
const indexes = range(this.viewItems.length).filter(i => i !== index);
1023+
const lowPriorityIndexes = [...indexes.filter(i => this.viewItems[i].priority === LayoutPriority.Low), index];
1024+
const highPriorityIndexes = indexes.filter(i => this.viewItems[i].priority === LayoutPriority.High);
1025+
1026+
this.relayout(lowPriorityIndexes, highPriorityIndexes);
10211027
}
10221028
}
10231029

src/vs/base/test/browser/ui/splitview/splitview.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class TestView implements IView<number> {
3636
private readonly _onDidFocus = new Emitter<void>();
3737
readonly onDidFocus = this._onDidFocus.event;
3838

39+
private readonly _onDidSetVisible = new Emitter<boolean>();
40+
readonly onDidSetVisible = this._onDidSetVisible.event;
41+
3942
constructor(
4043
private _minimumSize: number,
4144
private _maximumSize: number,
@@ -44,6 +47,17 @@ class TestView implements IView<number> {
4447
assert(_minimumSize <= _maximumSize, 'splitview view minimum size must be <= maximum size');
4548
}
4649

50+
/** Change both size constraints at once, as a view with a fixed width does when that width changes. */
51+
setSizeConstraints(minimumSize: number, maximumSize: number): void {
52+
this._minimumSize = minimumSize;
53+
this._maximumSize = maximumSize;
54+
this._onDidChange.fire(undefined);
55+
}
56+
57+
setVisible(visible: boolean): void {
58+
this._onDidSetVisible.fire(visible);
59+
}
60+
4761
layout(size: number, _offset: number, orthogonalSize: number | undefined): void {
4862
this._size = size;
4963
this._orthogonalSize = orthogonalSize;
@@ -59,6 +73,7 @@ class TestView implements IView<number> {
5973
this._onDidGetElement.dispose();
6074
this._onDidLayout.dispose();
6175
this._onDidFocus.dispose();
76+
this._onDidSetVisible.dispose();
6277
}
6378
}
6479

@@ -459,6 +474,32 @@ suite('Splitview', () => {
459474
assert.deepStrictEqual([view1.size, view2.size, view3.size], [20, 160, 20]);
460475
});
461476

477+
test('view changing its size constraints while a sibling is toggled does not squeeze that sibling (#334167)', () => {
478+
479+
// Mirrors the workbench with the side bar on the right: the activity bar reports its new fixed width from within the visibility change of the side bar
480+
const editor = store.add(new TestView(20, Number.POSITIVE_INFINITY, LayoutPriority.High));
481+
const sideBar = store.add(new TestView(20, Number.POSITIVE_INFINITY, LayoutPriority.Low));
482+
const activityBar = store.add(new TestView(10, 10));
483+
const splitview = store.add(new SplitView(container, { proportionalLayout: false }));
484+
splitview.layout(200);
485+
486+
splitview.addView(editor, 120);
487+
splitview.addView(sideBar, 70);
488+
splitview.addView(activityBar, 10);
489+
490+
// `addView` distributes in index order too, so restore the side bar to a known starting point
491+
splitview.resizeView(1, 70);
492+
assert.deepStrictEqual([editor.size, sideBar.size, activityBar.size], [120, 70, 10]);
493+
494+
store.add(sideBar.onDidSetVisible(visible => activityBar.setSizeConstraints(visible ? 10 : 12, visible ? 10 : 12)));
495+
496+
splitview.setViewVisible(1, false);
497+
assert.deepStrictEqual([editor.size, sideBar.size, activityBar.size], [188, 0, 12]);
498+
499+
splitview.setViewVisible(1, true);
500+
assert.deepStrictEqual([editor.size, sideBar.size, activityBar.size], [120, 70, 10]);
501+
});
502+
462503
test('context propagates to views', () => {
463504
const view1 = store.add(new TestView(20, Number.POSITIVE_INFINITY));
464505
const view2 = store.add(new TestView(20, Number.POSITIVE_INFINITY));

0 commit comments

Comments
 (0)