Merge from vscode e3c4990c67c40213af168300d1cfeb71d680f877 (#16569)

This commit is contained in:
Cory Rivera
2021-08-25 16:28:29 -07:00
committed by GitHub
parent ab1112bfb3
commit cb7b7da0a4
1752 changed files with 59525 additions and 33878 deletions

View File

@@ -9,9 +9,10 @@ import { Orientation, Sash } from 'vs/base/browser/ui/sash/sash';
import { SplitView, IView as ISplitView, Sizing, LayoutPriority, ISplitViewStyles } from 'vs/base/browser/ui/splitview/splitview';
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { $ } from 'vs/base/browser/dom';
import { tail2 as tail } from 'vs/base/common/arrays';
import { equals as arrayEquals, tail2 as tail } from 'vs/base/common/arrays';
import { Color } from 'vs/base/common/color';
import { clamp } from 'vs/base/common/numbers';
import { isUndefined } from 'vs/base/common/types';
export { Sizing, LayoutPriority } from 'vs/base/browser/ui/splitview/splitview';
export { Orientation } from 'vs/base/browser/ui/sash/sash';
@@ -242,6 +243,10 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
private readonly _onDidChange = new Emitter<number | undefined>();
readonly onDidChange: Event<number | undefined> = this._onDidChange.event;
private _onDidScroll = new Emitter<void>();
private onDidScrollDisposable: IDisposable = Disposable.None;
readonly onDidScroll: Event<void> = this._onDidScroll.event;
private childrenChangeDisposable: IDisposable = Disposable.None;
private readonly _onDidSashReset = new Emitter<number[]>();
@@ -343,11 +348,7 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
const onDidSashReset = Event.map(this.splitview.onDidSashReset, i => [i]);
this.splitviewSashResetDisposable = onDidSashReset(this._onDidSashReset.fire, this._onDidSashReset);
const onDidChildrenChange = Event.map(Event.any(...this.children.map(c => c.onDidChange)), () => undefined);
this.childrenChangeDisposable = onDidChildrenChange(this._onDidChange.fire, this._onDidChange);
const onDidChildrenSashReset = Event.any(...this.children.map((c, i) => Event.map(c.onDidSashReset, location => [i, ...location])));
this.childrenSashResetDisposable = onDidChildrenSashReset(this._onDidSashReset.fire, this._onDidSashReset);
this.updateChildrenEvents();
}
style(styles: IGridViewStyles): void {
@@ -566,6 +567,11 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
}
private onDidChildrenChange(): void {
this.updateChildrenEvents();
this._onDidChange.fire(undefined);
}
private updateChildrenEvents(): void {
const onDidChildrenChange = Event.map(Event.any(...this.children.map(c => c.onDidChange)), () => undefined);
this.childrenChangeDisposable.dispose();
this.childrenChangeDisposable = onDidChildrenChange(this._onDidChange.fire, this._onDidChange);
@@ -574,7 +580,9 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
this.childrenSashResetDisposable.dispose();
this.childrenSashResetDisposable = onDidChildrenSashReset(this._onDidSashReset.fire, this._onDidSashReset);
this._onDidChange.fire(undefined);
const onDidScroll = Event.any(Event.signal(this.splitview.onDidScroll), ...this.children.map(c => c.onDidScroll));
this.onDidScrollDisposable.dispose();
this.onDidScrollDisposable = onDidScroll(this._onDidScroll.fire, this._onDidScroll);
}
trySet2x2(other: BranchNode): IDisposable {
@@ -646,6 +654,25 @@ class BranchNode implements ISplitView<ILayoutContext>, IDisposable {
}
}
/**
* Creates a latched event that avoids being fired when the view
* constraints do not change at all.
*/
function createLatchedOnDidChangeViewEvent(view: IView): Event<IViewSize | undefined> {
const [onDidChangeViewConstraints, onDidSetViewSize] = Event.split<undefined, IViewSize>(view.onDidChange, isUndefined);
return Event.any(
onDidSetViewSize,
Event.map(
Event.latch(
Event.map(onDidChangeViewConstraints, _ => ([view.minimumWidth, view.maximumWidth, view.minimumHeight, view.maximumHeight])),
arrayEquals
),
_ => undefined
)
);
}
class LeafNode implements ISplitView<ILayoutContext>, IDisposable {
private _size: number = 0;
@@ -657,6 +684,7 @@ class LeafNode implements ISplitView<ILayoutContext>, IDisposable {
private absoluteOffset: number = 0;
private absoluteOrthogonalOffset: number = 0;
readonly onDidScroll: Event<void> = Event.None;
readonly onDidSashReset: Event<number[]> = Event.None;
private _onDidLinkedWidthNodeChange = new Relay<number | undefined>();
@@ -691,7 +719,8 @@ class LeafNode implements ISplitView<ILayoutContext>, IDisposable {
this._orthogonalSize = orthogonalSize;
this._size = size;
this._onDidViewChange = Event.map(this.view.onDidChange, e => e && (this.orientation === Orientation.VERTICAL ? e.width : e.height));
const onDidChange = createLatchedOnDidChangeViewEvent(view);
this._onDidViewChange = Event.map(onDidChange, e => e && (this.orientation === Orientation.VERTICAL ? e.width : e.height));
this.onDidChange = Event.any(this._onDidViewChange, this._onDidSetLinkedNode.event, this._onDidLinkedWidthNodeChange.event, this._onDidLinkedHeightNodeChange.event);
}
@@ -778,7 +807,25 @@ class LeafNode implements ISplitView<ILayoutContext>, IDisposable {
this._orthogonalSize = ctx.orthogonalSize;
this.absoluteOffset = ctx.absoluteOffset + offset;
this.absoluteOrthogonalOffset = ctx.absoluteOrthogonalOffset;
this.view.layout(this.width, this.height, this.top, this.left);
this._layout(this.width, this.height, this.top, this.left);
}
private cachedWidth: number = 0;
private cachedHeight: number = 0;
private cachedTop: number = 0;
private cachedLeft: number = 0;
private _layout(width: number, height: number, top: number, left: number): void {
if (this.cachedWidth === width && this.cachedHeight === height && this.cachedTop === top && this.cachedLeft === left) {
return;
}
this.cachedWidth = width;
this.cachedHeight = height;
this.cachedTop = top;
this.cachedLeft = left;
this.view.layout(width, height, top, left);
}
setVisible(visible: boolean): void {
@@ -852,6 +899,7 @@ export class GridView implements IDisposable {
this.element.appendChild(root.element);
this.onDidSashResetRelay.input = root.onDidSashReset;
this._onDidChange.input = Event.map(root.onDidChange, () => undefined); // TODO
this._onDidScroll.input = root.onDidScroll;
}
get orientation(): Orientation {
@@ -877,6 +925,9 @@ export class GridView implements IDisposable {
get maximumWidth(): number { return this.root.maximumHeight; }
get maximumHeight(): number { return this.root.maximumHeight; }
private _onDidScroll = new Relay<void>();
readonly onDidScroll = this._onDidScroll.event;
private _onDidChange = new Relay<IViewSize | undefined>();
readonly onDidChange = this._onDidChange.event;