Skip to content

Commit

Permalink
Fix webviews in same view column not always getting correct state cha…
Browse files Browse the repository at this point in the history
…nge fired for visibility

Fixes #70859
  • Loading branch information
mjbvz committed Apr 3, 2019
1 parent 4f03abc commit 06dd68b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/vs/workbench/api/electron-browser/mainThreadWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export class MainThreadWebviews extends Disposable implements MainThreadWebviews
};

this._webviews.set(handle, webview);
this._activeWebview = handle;

/* __GDPR__
"webviews:createWebviewPanel" : {
Expand Down
13 changes: 3 additions & 10 deletions src/vs/workbench/contrib/webview/browser/webviewEditorInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export class WebviewEditorInput extends EditorInput {

constructor(
public readonly viewType: string,
id: number,
name: string,
options: WebviewInputOptions,
state: any,
Expand All @@ -85,8 +84,7 @@ export class WebviewEditorInput extends EditorInput {
) {
super();

this._id = id;
WebviewEditorInput.handlePool = Math.max(id, WebviewEditorInput.handlePool) + 1;
this._id = WebviewEditorInput.handlePool++;

this._name = name;
this._options = options;
Expand All @@ -99,10 +97,6 @@ export class WebviewEditorInput extends EditorInput {
return WebviewEditorInput.typeId;
}

public getId(): number {
return this._id;
}

private readonly _onDidChangeIcon = this._register(new Emitter<void>());
public readonly onDidChangeIcon = this._onDidChangeIcon.event;

Expand Down Expand Up @@ -157,7 +151,7 @@ export class WebviewEditorInput extends EditorInput {
}

public matches(other: IEditorInput): boolean {
return other === this || (other instanceof WebviewEditorInput && other._id === this._id);
return other === this;
}

public get group(): GroupIdentifier | undefined {
Expand Down Expand Up @@ -312,7 +306,6 @@ export class RevivedWebviewEditorInput extends WebviewEditorInput {

constructor(
viewType: string,
id: number,
name: string,
options: WebviewInputOptions,
state: any,
Expand All @@ -324,7 +317,7 @@ export class RevivedWebviewEditorInput extends WebviewEditorInput {
private readonly reviver: (input: WebviewEditorInput) => Promise<void>,
@IWorkbenchLayoutService partService: IWorkbenchLayoutService,
) {
super(viewType, id, name, options, state, events, extension, partService);
super(viewType, name, options, state, events, extension, partService);
}

public async resolve(): Promise<IEditorModel> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interface SerializedIconPath {

interface SerializedWebview {
readonly viewType: string;
readonly id: number;
readonly title: string;
readonly options: WebviewInputOptions;
readonly extensionLocation: string | UriComponents | undefined;
Expand All @@ -44,7 +43,6 @@ export class WebviewEditorInputFactory implements IEditorInputFactory {

const data: SerializedWebview = {
viewType: input.viewType,
id: input.getId(),
title: input.getName(),
options: input.options,
extensionLocation: input.extension ? input.extension.location : undefined,
Expand All @@ -69,7 +67,7 @@ export class WebviewEditorInputFactory implements IEditorInputFactory {
const extensionLocation = reviveUri(data.extensionLocation);
const extensionId = data.extensionId ? new ExtensionIdentifier(data.extensionId) : undefined;
const iconPath = reviveIconPath(data.iconPath);
return this._webviewService.reviveWebview(data.viewType, data.id, data.title, iconPath, data.state, data.options, extensionLocation ? {
return this._webviewService.reviveWebview(data.viewType, data.title, iconPath, data.state, data.options, extensionLocation ? {
location: extensionLocation,
id: extensionId
} : undefined, data.group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export interface IWebviewEditorService {

reviveWebview(
viewType: string,
id: number,
title: string,
iconPath: { light: URI, dark: URI } | undefined,
state: any,
Expand Down Expand Up @@ -143,7 +142,7 @@ export class WebviewEditorService implements IWebviewEditorService {
},
events: WebviewEvents
): WebviewEditorInput {
const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, undefined, title, options, {}, events, extension);
const webviewInput = this._instantiationService.createInstance(WebviewEditorInput, viewType, title, options, {}, events, extension);
this._editorService.openEditor(webviewInput, { pinned: true, preserveFocus: showOptions.preserveFocus }, showOptions.group);
return webviewInput;
}
Expand All @@ -165,7 +164,6 @@ export class WebviewEditorService implements IWebviewEditorService {

public reviveWebview(
viewType: string,
id: number,
title: string,
iconPath: { light: URI, dark: URI } | undefined,
state: any,
Expand All @@ -176,7 +174,7 @@ export class WebviewEditorService implements IWebviewEditorService {
},
group: number | undefined,
): WebviewEditorInput {
const webviewInput = this._instantiationService.createInstance(RevivedWebviewEditorInput, viewType, id, title, options, state, {}, extension, async (webview: WebviewEditorInput): Promise<void> => {
const webviewInput = this._instantiationService.createInstance(RevivedWebviewEditorInput, viewType, title, options, state, {}, extension, async (webview: WebviewEditorInput): Promise<void> => {
const didRevive = await this.tryRevive(webview);
if (didRevive) {
return Promise.resolve(undefined);
Expand Down Expand Up @@ -220,7 +218,7 @@ export class WebviewEditorService implements IWebviewEditorService {

// Revived webviews may not have an actively registered reviver but we still want to presist them
// since a reviver should exist when it is actually needed.
return !(webview instanceof RevivedWebviewEditorInput);
return webview instanceof RevivedWebviewEditorInput;
}

private async tryRevive(
Expand Down

0 comments on commit 06dd68b

Please sign in to comment.