mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-02 06:21:50 +01:00
Reduce duplicate state for active webviews
This commit is contained in:
@@ -37,7 +37,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
|
||||
private readonly _webviews = new Map<WebviewHandle, WebviewEditorInput>();
|
||||
private readonly _revivers = new Set<string>();
|
||||
|
||||
private _activeWebview: WebviewEditorInput | undefined = undefined;
|
||||
private _activeWebview: WebviewHandle | undefined = undefined;
|
||||
|
||||
constructor(
|
||||
context: IExtHostContext,
|
||||
@@ -175,7 +175,6 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
|
||||
return {
|
||||
onDidClickLink: uri => this.onDidClickLink(handle, uri),
|
||||
onMessage: message => this._proxy.$onMessage(handle, message),
|
||||
onDidChangePosition: position => this._proxy.$onDidChangePosition(handle, position),
|
||||
onDispose: () => {
|
||||
this._proxy.$onDidDisposeWeview(handle).then(() => {
|
||||
this._webviews.delete(handle);
|
||||
@@ -205,16 +204,25 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv
|
||||
}
|
||||
}
|
||||
|
||||
if (newActiveWebview && newActiveWebview.handle === this._activeWebview) {
|
||||
// No change
|
||||
return;
|
||||
}
|
||||
|
||||
// Broadcast view state update for currently active
|
||||
if (typeof this._activeWebview !== 'undefined') {
|
||||
const oldActiveWebview = this._webviews.get(this._activeWebview);
|
||||
if (oldActiveWebview) {
|
||||
this._proxy.$onDidChangeWeviewViewState(this._activeWebview, false, oldActiveWebview.position);
|
||||
}
|
||||
}
|
||||
|
||||
// Then for newly active
|
||||
if (newActiveWebview) {
|
||||
if (!this._activeWebview || newActiveWebview.input !== this._activeWebview) {
|
||||
this._proxy.$onDidChangeActiveWeview(newActiveWebview.handle);
|
||||
this._activeWebview = newActiveWebview.input;
|
||||
}
|
||||
this._proxy.$onDidChangeWeviewViewState(newActiveWebview.handle, true, activeEditor.position);
|
||||
this._activeWebview = newActiveWebview.handle;
|
||||
} else {
|
||||
if (this._activeWebview) {
|
||||
this._proxy.$onDidChangeActiveWeview(undefined);
|
||||
this._activeWebview = undefined;
|
||||
}
|
||||
this._activeWebview = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user