Skip to content

Commit 60dea40

Browse files
committed
grid: generalize boundary sashes
1 parent ae78db0 commit 60dea40

2 files changed

Lines changed: 57 additions & 22 deletions

File tree

src/vs/base/browser/ui/grid/gridview.ts

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export interface IViewSize {
2121
readonly height: number;
2222
}
2323

24+
interface IBoundarySashes {
25+
readonly start?: Sash;
26+
readonly end?: Sash;
27+
readonly orthogonalStart?: Sash;
28+
readonly orthogonalEnd?: Sash;
29+
}
30+
2431
export interface IView {
2532
readonly element: HTMLElement;
2633
readonly minimumWidth: number;
@@ -217,10 +224,14 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
217224
private splitviewSashResetDisposable: IDisposable = Disposable.None;
218225
private childrenSashResetDisposable: IDisposable = Disposable.None;
219226

220-
get orthogonalStartSash(): Sash | undefined { return this.splitview.orthogonalStartSash; }
221-
set orthogonalStartSash(sash: Sash | undefined) { this.splitview.orthogonalStartSash = sash; }
222-
get orthogonalEndSash(): Sash | undefined { return this.splitview.orthogonalEndSash; }
223-
set orthogonalEndSash(sash: Sash | undefined) { this.splitview.orthogonalEndSash = sash; }
227+
private _boundarySashes: IBoundarySashes = {};
228+
get boundarySashes(): IBoundarySashes { return this._boundarySashes; }
229+
set boundarySashes(boundarySashes: IBoundarySashes) {
230+
this._boundarySashes = boundarySashes;
231+
232+
this.splitview.orthogonalStartSash = boundarySashes.orthogonalStart;
233+
this.splitview.orthogonalEndSash = boundarySashes.orthogonalEnd;
234+
}
224235

225236
constructor(
226237
readonly orientation: Orientation,
@@ -260,9 +271,15 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
260271
this.splitview = new SplitView(this.element, { ...options, descriptor });
261272

262273
this.children.forEach((node, index) => {
263-
// Set up orthogonal sashes for children
264-
node.orthogonalStartSash = this.splitview.sashes[index - 1];
265-
node.orthogonalEndSash = this.splitview.sashes[index];
274+
const first = index === 0;
275+
const last = index === this.children.length;
276+
277+
node.boundarySashes = {
278+
start: this.boundarySashes.orthogonalStart,
279+
end: this.boundarySashes.orthogonalEnd,
280+
orthogonalStart: first ? this.boundarySashes.start : this.splitview.sashes[index - 1],
281+
orthogonalEnd: last ? this.boundarySashes.end : this.splitview.sashes[index],
282+
};
266283
});
267284
}
268285

@@ -335,15 +352,26 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
335352
const first = index === 0;
336353
const last = index === this.children.length;
337354
this.children.splice(index, 0, node);
338-
node.orthogonalStartSash = this.splitview.sashes[index - 1];
339-
node.orthogonalEndSash = this.splitview.sashes[index];
355+
356+
node.boundarySashes = {
357+
start: this.boundarySashes.orthogonalStart,
358+
end: this.boundarySashes.orthogonalEnd,
359+
orthogonalStart: first ? this.boundarySashes.start : this.splitview.sashes[index - 1],
360+
orthogonalEnd: last ? this.boundarySashes.end : this.splitview.sashes[index],
361+
};
340362

341363
if (!first) {
342-
this.children[index - 1].orthogonalEndSash = this.splitview.sashes[index - 1];
364+
this.children[index - 1].boundarySashes = {
365+
...this.children[index - 1].boundarySashes,
366+
orthogonalEnd: this.splitview.sashes[index - 1]
367+
};
343368
}
344369

345370
if (!last) {
346-
this.children[index + 1].orthogonalStartSash = this.splitview.sashes[index];
371+
this.children[index + 1].boundarySashes = {
372+
...this.children[index + 1].boundarySashes,
373+
orthogonalStart: this.splitview.sashes[index]
374+
};
347375
}
348376
}
349377

@@ -363,11 +391,17 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
363391
const [child] = this.children.splice(index, 1);
364392

365393
if (!first) {
366-
this.children[index - 1].orthogonalEndSash = this.splitview.sashes[index - 1];
394+
this.children[index - 1].boundarySashes = {
395+
...this.children[index - 1].boundarySashes,
396+
orthogonalEnd: this.splitview.sashes[index - 1]
397+
};
367398
}
368399

369400
if (!last) { // [0,1,2,3] (2) => [0,1,3]
370-
this.children[index].orthogonalStartSash = this.splitview.sashes[Math.max(index - 1, 0)];
401+
this.children[index].boundarySashes = {
402+
...this.children[index].boundarySashes,
403+
orthogonalStart: this.splitview.sashes[Math.max(index - 1, 0)]
404+
};
371405
}
372406

373407
return child;
@@ -408,7 +442,12 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
408442
to = clamp(to, 0, this.children.length);
409443

410444
this.splitview.swapViews(from, to);
411-
[this.children[from].orthogonalStartSash, this.children[from].orthogonalEndSash, this.children[to].orthogonalStartSash, this.children[to].orthogonalEndSash] = [this.children[to].orthogonalStartSash, this.children[to].orthogonalEndSash, this.children[from].orthogonalStartSash, this.children[from].orthogonalEndSash];
445+
446+
// swap boundary sashes
447+
[this.children[from].boundarySashes, this.children[to].boundarySashes]
448+
= [this.children[from].boundarySashes, this.children[to].boundarySashes];
449+
450+
// swap children
412451
[this.children[from], this.children[to]] = [this.children[to], this.children[from]];
413452

414453
this.onDidChildrenChange();
@@ -655,13 +694,9 @@ class LeafNode implements ISplitView<ILayoutContext>, IDisposable {
655694
return this.orientation === Orientation.HORIZONTAL ? this.maximumWidth : this.maximumHeight;
656695
}
657696

658-
set orthogonalStartSash(sash: Sash) {
659-
// noop
660-
}
661-
662-
set orthogonalEndSash(sash: Sash) {
663-
// noop
664-
}
697+
private _boundarySashes: IBoundarySashes = {};
698+
get boundarySashes(): IBoundarySashes { return this._boundarySashes; }
699+
set boundarySashes(boundarySashes: IBoundarySashes) { this._boundarySashes = boundarySashes; }
665700

666701
layout(size: number, offset: number, ctx: ILayoutContext | undefined): void {
667702
if (!this.layoutController.isLayoutEnabled) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Event, Emitter } from 'vs/base/common/event';
1414
import { getElementsByTagName, EventHelper, createStyleSheet, addDisposableListener, append, $, addClass, removeClass, toggleClass } from 'vs/base/browser/dom';
1515
import { domEvent } from 'vs/base/browser/event';
1616

17-
const DEBUG = false;
17+
const DEBUG = true;
1818

1919
export interface ISashLayoutProvider { }
2020

0 commit comments

Comments
 (0)