提交 528da15d 编写于 作者: J Johannes Rieken

perf - avoid layout trashing in breadcrumbs

上级 23fe4acb
...@@ -551,6 +551,16 @@ export class Dimension { ...@@ -551,6 +551,16 @@ export class Dimension {
this.width = width; this.width = width;
this.height = height; this.height = height;
} }
static equals(a: Dimension, b: Dimension): boolean {
if (a === b) {
return true;
}
if (!a || !b) {
return false;
}
return a.width === b.width && a.height === b.height;
}
} }
export function getTopLeftOffset(element: HTMLElement): { left: number; top: number; } { export function getTopLeftOffset(element: HTMLElement): { left: number; top: number; } {
......
...@@ -77,6 +77,9 @@ export class BreadcrumbsWidget { ...@@ -77,6 +77,9 @@ export class BreadcrumbsWidget {
private _focusedItemIdx: number = -1; private _focusedItemIdx: number = -1;
private _selectedItemIdx: number = -1; private _selectedItemIdx: number = -1;
private _pendingLayout: IDisposable;
private _dimension: dom.Dimension;
constructor( constructor(
container: HTMLElement container: HTMLElement
) { ) {
...@@ -105,6 +108,7 @@ export class BreadcrumbsWidget { ...@@ -105,6 +108,7 @@ export class BreadcrumbsWidget {
dispose(): void { dispose(): void {
dispose(this._disposables); dispose(this._disposables);
dispose(this._pendingLayout);
this._onDidSelectItem.dispose(); this._onDidSelectItem.dispose();
this._onDidFocusItem.dispose(); this._onDidFocusItem.dispose();
this._onDidChangeFocus.dispose(); this._onDidChangeFocus.dispose();
...@@ -115,13 +119,20 @@ export class BreadcrumbsWidget { ...@@ -115,13 +119,20 @@ export class BreadcrumbsWidget {
} }
layout(dim: dom.Dimension): void { layout(dim: dom.Dimension): void {
if (dom.Dimension.equals(dim, this._dimension)) {
return;
}
this._dimension = dim;
if (dim) { if (dim) {
this._domNode.style.width = `${dim.width}px`; this._domNode.style.width = `${dim.width}px`;
this._domNode.style.height = `${dim.height}px`; this._domNode.style.height = `${dim.height}px`;
} }
dispose(this._pendingLayout);
this._pendingLayout = dom.scheduleAtNextAnimationFrame(() => {
this._scrollable.setRevealOnScroll(false); this._scrollable.setRevealOnScroll(false);
this._scrollable.scanDomNode(); this._scrollable.scanDomNode();
this._scrollable.setRevealOnScroll(true); this._scrollable.setRevealOnScroll(true);
});
} }
style(style: IBreadcrumbsWidgetStyles): void { style(style: IBreadcrumbsWidgetStyles): void {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册