Move webview animation workaround to viewPane (#163675)

This workaround is only required for webview views, so let's move the code there
This commit is contained in:
Matt Bierner
2022-10-14 11:12:46 -07:00
committed by GitHub
parent 8dfd89e065
commit 46e6b68743
2 changed files with 11 additions and 16 deletions
@@ -31,7 +31,6 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
private _html: string = '';
private _initialScrollProgress: number = 0;
private _state: string | undefined = undefined;
private _repositionTimeout: any | undefined = undefined;
private _extension: WebviewExtensionDescription | undefined;
private _contentOptions: WebviewContentOptions;
@@ -85,8 +84,6 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
}
this._firstLoadPendingMessages.clear();
clearTimeout(this._repositionTimeout);
this._onDidDispose.fire();
super.dispose();
@@ -163,17 +160,6 @@ export class OverlayWebview extends Disposable implements IOverlayWebview {
}
public layoutWebviewOverElement(element: HTMLElement, dimension?: Dimension, clippingContainer?: HTMLElement) {
this.doLayoutWebviewOverElement(element, dimension, clippingContainer);
// Temporary fix for https://github.com/microsoft/vscode/issues/110450
// There is an animation that lasts about 200ms, update the webview positioning once this animation is complete.
clearTimeout(this._repositionTimeout);
this._repositionTimeout = setTimeout(() => {
this.doLayoutWebviewOverElement(element, dimension, clippingContainer);
}, 200);
}
public doLayoutWebviewOverElement(element: HTMLElement, dimension?: Dimension, clippingContainer?: HTMLElement) {
if (!this._container || !this._container.parentElement) {
return;
}
@@ -63,6 +63,8 @@ export class WebviewViewPane extends ViewPane {
private readonly viewState: MementoObject;
private readonly extensionId?: ExtensionIdentifier;
private _repositionTimeout?: any;
constructor(
options: IViewletViewOptions,
@IConfigurationService configurationService: IConfigurationService,
@@ -110,6 +112,8 @@ export class WebviewViewPane extends ViewPane {
override dispose() {
this._onDispose.fire();
clearTimeout(this._repositionTimeout);
super.dispose();
}
@@ -286,16 +290,21 @@ export class WebviewViewPane extends ViewPane {
return;
}
webviewEntry.layoutWebviewOverElement(this._container);
if (!this._rootContainer || !this._rootContainer.isConnected) {
this._rootContainer = this.findRootContainer(this._container);
}
webviewEntry.layoutWebviewOverElement(this._container);
if (this._rootContainer) {
const { top, left, right, bottom } = computeClippingRect(this._container, this._rootContainer);
webviewEntry.container.style.clipPath = `polygon(${left}px ${top}px, ${right}px ${top}px, ${right}px ${bottom}px, ${left}px ${bottom}px)`;
}
// Temporary fix for https://github.com/microsoft/vscode/issues/110450
// There is an animation that lasts about 200ms, update the webview positioning once this animation is complete.
clearTimeout(this._repositionTimeout);
this._repositionTimeout = setTimeout(() => this.layoutWebview(), 200);
}
private findRootContainer(container: HTMLElement): HTMLElement | undefined {