Skip to content

Commit 657436a

Browse files
committed
Make sure restored custom editors correctly track being dirty even if they have not been activated yet
1 parent cb1ce16 commit 657436a

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
2727
public static typeId = 'workbench.editors.webviewEditor';
2828

2929
private readonly _editorResource: URI;
30-
private readonly _fromBackup: boolean;
30+
private readonly _startsDirty: boolean | undefined;
3131

3232
get resource() { return this._editorResource; }
3333

@@ -38,7 +38,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
3838
viewType: string,
3939
id: string,
4040
webview: Lazy<WebviewOverlay>,
41-
fromBackup: boolean,
41+
options: { startsDirty?: boolean },
4242
@IWebviewService webviewService: IWebviewService,
4343
@IWebviewWorkbenchService webviewWorkbenchService: IWebviewWorkbenchService,
4444
@IInstantiationService private readonly instantiationService: IInstantiationService,
@@ -51,7 +51,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
5151
) {
5252
super(id, viewType, '', webview, webviewService, webviewWorkbenchService);
5353
this._editorResource = resource;
54-
this._fromBackup = fromBackup;
54+
this._startsDirty = options.startsDirty;
5555
}
5656

5757
public getTypeId(): string {
@@ -110,7 +110,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
110110

111111
public isDirty(): boolean {
112112
if (!this._modelRef) {
113-
return this._fromBackup;
113+
return !!this._startsDirty;
114114
}
115115
return this._modelRef.object.isDirty();
116116
}
@@ -201,7 +201,7 @@ export class CustomEditorInput extends LazilyResolvedWebviewEditorInput {
201201
this.viewType,
202202
this.id,
203203
new Lazy(() => undefined!),
204-
this._fromBackup); // this webview is replaced in the transfer call
204+
{ startsDirty: this._startsDirty }); // this webview is replaced in the transfer call
205205
this.transfer(newEditor);
206206
newEditor.updateGroup(group);
207207
return newEditor;

src/vs/workbench/contrib/customEditor/browser/customEditorInputFactory.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
1111
import { IEditorInput } from 'vs/workbench/common/editor';
1212
import { CustomEditorInput } from 'vs/workbench/contrib/customEditor/browser/customEditorInput';
1313
import { IWebviewService } from 'vs/workbench/contrib/webview/browser/webview';
14-
import { WebviewEditorInputFactory } from 'vs/workbench/contrib/webview/browser/webviewEditorInputFactory';
14+
import { WebviewEditorInputFactory, SerializedWebview } from 'vs/workbench/contrib/webview/browser/webviewEditorInputFactory';
1515
import { IWebviewWorkbenchService, WebviewInputOptions } from 'vs/workbench/contrib/webview/browser/webviewWorkbenchService';
1616
import { IBackupFileService } from 'vs/workbench/services/backup/common/backup';
1717

@@ -30,6 +30,12 @@ export interface CustomDocumentBackupData {
3030
};
3131
}
3232

33+
interface SerializedCustomEditor extends SerializedWebview {
34+
readonly editorResource: UriComponents;
35+
readonly dirty?: boolean;
36+
}
37+
38+
3339
export class CustomEditorInputFactory extends WebviewEditorInputFactory {
3440

3541
public static readonly ID = CustomEditorInput.typeId;
@@ -43,9 +49,10 @@ export class CustomEditorInputFactory extends WebviewEditorInputFactory {
4349
}
4450

4551
public serialize(input: CustomEditorInput): string | undefined {
46-
const data = {
52+
const data: SerializedCustomEditor = {
4753
...this.toJson(input),
4854
editorResource: input.resource.toJSON(),
55+
dirty: input.isDirty(),
4956
};
5057

5158
try {
@@ -78,7 +85,7 @@ export class CustomEditorInputFactory extends WebviewEditorInputFactory {
7885
return webview;
7986
});
8087

81-
const customInput = this._instantiationService.createInstance(CustomEditorInput, URI.from((data as any).editorResource), data.viewType, id, webview, false);
88+
const customInput = this._instantiationService.createInstance(CustomEditorInput, URI.from((data as any).editorResource), data.viewType, id, webview, { startsDirty: (data as any).dirty });
8289
if (typeof data.group === 'number') {
8390
customInput.updateGroup(data.group);
8491
}
@@ -112,7 +119,7 @@ export class CustomEditorInputFactory extends WebviewEditorInputFactory {
112119
return webview;
113120
});
114121

115-
const editor = instantiationService.createInstance(CustomEditorInput, URI.revive(backupData.editorResource), backupData.viewType, id, webview, true);
122+
const editor = instantiationService.createInstance(CustomEditorInput, URI.revive(backupData.editorResource), backupData.viewType, id, webview, { startsDirty: true });
116123
editor.updateGroup(0);
117124
return editor;
118125
});

src/vs/workbench/contrib/customEditor/browser/customEditors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
269269
const webview = new Lazy(() => {
270270
return this.webviewService.createWebviewOverlay(id, { customClasses: options?.customClasses }, {});
271271
});
272-
const input = this.instantiationService.createInstance(CustomEditorInput, resource, viewType, id, webview, false);
272+
const input = this.instantiationService.createInstance(CustomEditorInput, resource, viewType, id, webview, {});
273273
if (typeof group !== 'undefined') {
274274
input.updateGroup(group);
275275
}

src/vs/workbench/contrib/webview/browser/webviewEditorInputFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface SerializedIconPath {
1616
dark: string | UriComponents;
1717
}
1818

19-
interface SerializedWebview {
19+
export interface SerializedWebview {
2020
readonly id?: string;
2121
readonly viewType: string;
2222
readonly title: string;

0 commit comments

Comments
 (0)