Skip to content

Commit cf30025

Browse files
authored
Fix sash corners when moving views around (microsoft#186624)
fixes microsoft#186508
1 parent c6567bc commit cf30025

File tree

2 files changed

+34
-54
lines changed

2 files changed

+34
-54
lines changed

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

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
356356
private _boundarySashes: IRelativeBoundarySashes = {};
357357
get boundarySashes(): IRelativeBoundarySashes { return this._boundarySashes; }
358358
set boundarySashes(boundarySashes: IRelativeBoundarySashes) {
359+
if (this._boundarySashes.start === boundarySashes.start
360+
&& this._boundarySashes.end === boundarySashes.end
361+
&& this._boundarySashes.orthogonalStart === boundarySashes.orthogonalStart
362+
&& this._boundarySashes.orthogonalEnd === boundarySashes.orthogonalEnd) {
363+
return;
364+
}
365+
359366
this._boundarySashes = boundarySashes;
360367

361368
this.splitview.orthogonalStartSash = boundarySashes.orthogonalStart;
@@ -498,65 +505,20 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
498505
index = validateIndex(index, this.children.length);
499506

500507
this.splitview.addView(node, size, index, skipLayout);
501-
this._addChild(node, index);
502-
this.onDidChildrenChange();
503-
}
504-
505-
private _addChild(node: Node, index: number): void {
506-
const first = index === 0;
507-
const last = index === this.children.length;
508508
this.children.splice(index, 0, node);
509509

510-
node.boundarySashes = {
511-
start: this.boundarySashes.orthogonalStart,
512-
end: this.boundarySashes.orthogonalEnd,
513-
orthogonalStart: first ? this.boundarySashes.start : this.splitview.sashes[index - 1],
514-
orthogonalEnd: last ? this.boundarySashes.end : this.splitview.sashes[index],
515-
};
516-
517-
if (!first) {
518-
this.children[index - 1].boundarySashes = {
519-
...this.children[index - 1].boundarySashes,
520-
orthogonalEnd: this.splitview.sashes[index - 1]
521-
};
522-
}
523-
524-
if (!last) {
525-
this.children[index + 1].boundarySashes = {
526-
...this.children[index + 1].boundarySashes,
527-
orthogonalStart: this.splitview.sashes[index]
528-
};
529-
}
510+
this.updateBoundarySashes();
511+
this.onDidChildrenChange();
530512
}
531513

532514
removeChild(index: number, sizing?: Sizing): void {
533515
index = validateIndex(index, this.children.length);
534516

535517
this.splitview.removeView(index, sizing);
536-
this._removeChild(index);
537-
this.onDidChildrenChange();
538-
}
518+
this.children.splice(index, 1);
539519

540-
private _removeChild(index: number): Node {
541-
const first = index === 0;
542-
const last = index === this.children.length - 1;
543-
const [child] = this.children.splice(index, 1);
544-
545-
if (!first) {
546-
this.children[index - 1].boundarySashes = {
547-
...this.children[index - 1].boundarySashes,
548-
orthogonalEnd: this.splitview.sashes[index - 1]
549-
};
550-
}
551-
552-
if (!last) { // [0,1,2,3] (2) => [0,1,3]
553-
this.children[index].boundarySashes = {
554-
...this.children[index].boundarySashes,
555-
orthogonalStart: this.splitview.sashes[Math.max(index - 1, 0)]
556-
};
557-
}
558-
559-
return child;
520+
this.updateBoundarySashes();
521+
this.onDidChildrenChange();
560522
}
561523

562524
moveChild(from: number, to: number): void {
@@ -568,14 +530,13 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
568530
}
569531

570532
if (from < to) {
571-
to--;
533+
to -= 1;
572534
}
573535

574536
this.splitview.moveView(from, to);
537+
this.children.splice(to, 0, this.children.splice(from, 1)[0]);
575538

576-
const child = this._removeChild(from);
577-
this._addChild(child, to);
578-
539+
this.updateBoundarySashes();
579540
this.onDidChildrenChange();
580541
}
581542

@@ -649,6 +610,17 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
649610
return this.splitview.getViewCachedVisibleSize(index);
650611
}
651612

613+
private updateBoundarySashes(): void {
614+
for (let i = 0; i < this.children.length; i++) {
615+
this.children[i].boundarySashes = {
616+
start: this.boundarySashes.orthogonalStart,
617+
end: this.boundarySashes.orthogonalEnd,
618+
orthogonalStart: i === 0 ? this.boundarySashes.start : this.splitview.sashes[i - 1],
619+
orthogonalEnd: i === this.children.length - 1 ? this.boundarySashes.end : this.splitview.sashes[i],
620+
};
621+
}
622+
}
623+
652624
private onDidChildrenChange(): void {
653625
this.updateChildrenEvents();
654626
this._onDidChange.fire(undefined);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ export class Sash extends Disposable {
328328
* The start of a vertical sash is its top-most position.
329329
*/
330330
set orthogonalStartSash(sash: Sash | undefined) {
331+
if (this._orthogonalStartSash === sash) {
332+
return;
333+
}
334+
331335
this.orthogonalStartDragHandleDisposables.clear();
332336
this.orthogonalStartSashDisposables.clear();
333337

@@ -362,6 +366,10 @@ export class Sash extends Disposable {
362366
*/
363367

364368
set orthogonalEndSash(sash: Sash | undefined) {
369+
if (this._orthogonalEndSash === sash) {
370+
return;
371+
}
372+
365373
this.orthogonalEndDragHandleDisposables.clear();
366374
this.orthogonalEndSashDisposables.clear();
367375

0 commit comments

Comments
 (0)