diff --git a/src/vs/workbench/browser/parts/editor/editorActions.ts b/src/vs/workbench/browser/parts/editor/editorActions.ts index 621adcab2cdd6be95fdd8b37698d4e28cb21789e..89bf027eb3a9996c6cacfa8e822e32a832341256 100644 --- a/src/vs/workbench/browser/parts/editor/editorActions.ts +++ b/src/vs/workbench/browser/parts/editor/editorActions.ts @@ -543,13 +543,13 @@ export class RevertAndCloseEditorAction extends Action { // first try a normal revert where the contents of the editor are restored try { - await editor.revert(); + await editor.revert(group.id); } catch (error) { // if that fails, since we are about to close the editor, we accept that // the editor cannot be reverted and instead do a soft revert that just // enables us to close the editor. With this, a user can always close a // dirty editor even when reverting fails. - await editor.revert({ soft: true }); + await editor.revert(group.id, { soft: true }); } group.closeEditor(editor); diff --git a/src/vs/workbench/browser/parts/editor/editorGroupView.ts b/src/vs/workbench/browser/parts/editor/editorGroupView.ts index 6de26a8919b65435481ee177e64b0b843acd9a6a..4e1ef44c83841d6cd5f8944b486a8002265e9e26 100644 --- a/src/vs/workbench/browser/parts/editor/editorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor/editorGroupView.ts @@ -1330,7 +1330,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { // Otherwise, handle accordingly switch (res) { case ConfirmResult.SAVE: - const result = await editor.save(this._group.id, { reason: SaveReason.EXPLICIT, context: SaveContext.EDITOR_CLOSE }); + const result = await editor.save(this.id, { reason: SaveReason.EXPLICIT, context: SaveContext.EDITOR_CLOSE }); return !result; case ConfirmResult.DONT_SAVE: @@ -1338,7 +1338,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { try { // first try a normal revert where the contents of the editor are restored - const result = await editor.revert(); + const result = await editor.revert(this.id); return !result; } catch (error) { @@ -1346,7 +1346,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView { // the editor cannot be reverted and instead do a soft revert that just // enables us to close the editor. With this, a user can always close a // dirty editor even when reverting fails. - const result = await editor.revert({ soft: true }); + const result = await editor.revert(this.id, { soft: true }); return !result; } diff --git a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts index ab700375161b3fb9c930b96b45392625615a5811..f23aacde1629102b52f621c456cc1c829f5ee32f 100644 --- a/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts +++ b/src/vs/workbench/browser/parts/titlebar/titlebarPart.ts @@ -16,7 +16,7 @@ import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/co import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { DisposableStore, dispose } from 'vs/base/common/lifecycle'; import * as nls from 'vs/nls'; -import { EditorInput, toResource, Verbosity, SideBySideEditor } from 'vs/workbench/common/editor'; +import { toResource, Verbosity, SideBySideEditor } from 'vs/workbench/common/editor'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IWorkspaceContextService, WorkbenchState, IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; import { IThemeService, registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platform/theme/common/themeService'; @@ -195,7 +195,7 @@ export class TitlebarPart extends Part implements ITitleService { // Apply listener for dirty and label changes const activeEditor = this.editorService.activeEditor; - if (activeEditor instanceof EditorInput) { + if (activeEditor) { this.activeEditorListeners.add(activeEditor.onDidChangeDirty(() => this.titleUpdater.schedule())); this.activeEditorListeners.add(activeEditor.onDidChangeLabel(() => this.titleUpdater.schedule())); } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 055db825de2625485961c34a8dcf3bae7afeccc8..a14a5ea456c300eb61ffe0bd3ee216aebf389190 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -362,6 +362,16 @@ export interface IEditorInput extends IDisposable { */ readonly onDispose: Event; + /** + * Triggered when this input changes its dirty state. + */ + readonly onDidChangeDirty: Event; + + /** + * Triggered when this input changes its label + */ + readonly onDidChangeLabel: Event; + /** * Returns the associated resource of this input. */ @@ -416,9 +426,9 @@ export interface IEditorInput extends IDisposable { isSaving(): boolean; /** - * Saves the editor. The provided groupId helps - * implementors to e.g. preserve view state of the editor - * and re-open it in the correct group after saving. + * Saves the editor. The provided groupId helps implementors + * to e.g. preserve view state of the editor and re-open it + * in the correct group after saving. */ save(groupId: GroupIdentifier, options?: ISaveOptions): Promise; @@ -430,9 +440,9 @@ export interface IEditorInput extends IDisposable { saveAs(groupId: GroupIdentifier, options?: ISaveOptions): Promise; /** - * Reverts this input. + * Reverts this input from the provided group. */ - revert(options?: IRevertOptions): Promise; + revert(group: GroupIdentifier, options?: IRevertOptions): Promise; /** * Returns if the other object matches this input. @@ -532,7 +542,7 @@ export abstract class EditorInput extends Disposable implements IEditorInput { return true; } - async revert(options?: IRevertOptions): Promise { + async revert(group: GroupIdentifier, options?: IRevertOptions): Promise { return true; } @@ -614,6 +624,10 @@ export abstract class TextEditorInput extends EditorInput { return true; } + + revert(group: GroupIdentifier, options?: IRevertOptions): Promise { + return this.textFileService.revert(this.resource, options); + } } export const enum EncodingMode { @@ -743,8 +757,8 @@ export class SideBySideEditorInput extends EditorInput { return this.master.saveAs(groupId, options); } - revert(options?: IRevertOptions): Promise { - return this.master.revert(options); + revert(group: GroupIdentifier, options?: IRevertOptions): Promise { + return this.master.revert(group, options); } getTelemetryDescriptor(): { [key: string]: unknown } { diff --git a/src/vs/workbench/common/editor/untitledTextEditorInput.ts b/src/vs/workbench/common/editor/untitledTextEditorInput.ts index 1ef371be66f27a53da28e3e00e97bd4f0ab6f641..29761f55cec1c1b5bba86b2c4729d0e9ba0d603d 100644 --- a/src/vs/workbench/common/editor/untitledTextEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledTextEditorInput.ts @@ -193,7 +193,7 @@ export class UntitledTextEditorInput extends TextEditorInput implements IEncodin return this.doSaveAs(group, options, () => this.textFileService.saveAs(this.resource, undefined, options), true /* replace editor across all groups */); } - async revert(options?: IRevertOptions): Promise { + async revert(group: GroupIdentifier, options?: IRevertOptions): Promise { if (this.cachedModel) { this.cachedModel.revert(); } diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts index b8cb60b0b6264341b8ab3d2dbfbe5b5aadc80933..552ed8f2507da2717f380ef7376c6b2440a67a3e 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts @@ -149,7 +149,7 @@ export class CustomFileEditorInput extends LazilyResolvedWebviewEditorInput { return true; } - public revert(options?: IRevertOptions): Promise { + public revert(group: GroupIdentifier, options?: IRevertOptions): Promise { return this._model ? this._model.revert(options) : Promise.resolve(false); } diff --git a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts index e4656bacabcca7c227f6caec68f32b6eb525543a..372492b034c3f005836c1683b13c5d5c300dcb8b 100644 --- a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts +++ b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts @@ -7,7 +7,7 @@ import { localize } from 'vs/nls'; import { createMemoizer } from 'vs/base/common/decorators'; import { dirname } from 'vs/base/common/resources'; import { URI } from 'vs/base/common/uri'; -import { EncodingMode, IFileEditorInput, ITextEditorModel, Verbosity, TextEditorInput, IRevertOptions } from 'vs/workbench/common/editor'; +import { EncodingMode, IFileEditorInput, ITextEditorModel, Verbosity, TextEditorInput } from 'vs/workbench/common/editor'; import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel'; import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel'; import { FileOperationError, FileOperationResult, IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files'; @@ -262,10 +262,6 @@ export class FileEditorInput extends TextEditorInput implements IFileEditorInput return false; } - revert(options?: IRevertOptions): Promise { - return this.textFileService.revert(this.resource, options); - } - getPreferredEditorId(candidates: string[]): string { return this.forceOpenAs === ForceOpenAs.Binary ? BINARY_FILE_EDITOR_ID : TEXT_FILE_EDITOR_ID; } diff --git a/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts b/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts index d1a86fceb9aa82ac683e83c73af54910cba10dc8..4a059d873ec809dbaba54dd1bd4b0556c59d8fdb 100644 --- a/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts +++ b/src/vs/workbench/contrib/files/test/browser/fileEditorInput.test.ts @@ -152,7 +152,7 @@ suite('Files - FileEditorInput', () => { resolved.textEditorModel!.setValue('changed'); assert.ok(input.isDirty()); - assert.ok(await input.revert()); + assert.ok(await input.revert(0)); assert.ok(!input.isDirty()); input.dispose(); diff --git a/src/vs/workbench/contrib/search/browser/searchEditorInput.ts b/src/vs/workbench/contrib/search/browser/searchEditorInput.ts index 018f83bc0a9d4912b3358ce988ad55cc278cb29f..93e8033c27b1498524a5b2b1c7d13b09f7287ee2 100644 --- a/src/vs/workbench/contrib/search/browser/searchEditorInput.ts +++ b/src/vs/workbench/contrib/search/browser/searchEditorInput.ts @@ -79,7 +79,7 @@ export class SearchEditorInput extends EditorInput { isDirty: () => this.isDirty(), backup: () => this.backup(), save: (options) => this.save(0, options), - revert: () => this.revert(), + revert: () => this.revert(0), }; this.workingCopyService.registerWorkingCopy(workingCopyAdapter); @@ -181,9 +181,9 @@ export class SearchEditorInput extends EditorInput { return false; } - async revert(options?: IRevertOptions) { + async revert(group: GroupIdentifier, options?: IRevertOptions) { // TODO: this should actually revert the contents. But it needs to set dirty false. - super.revert(options); + super.revert(group, options); this.setDirty(false); return true; } diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index e946a5dfc90d8354a0da80b00242a03b385aac44..8793d7cbf19592def763c0ae9e8a435fc3a549e2 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -737,7 +737,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Use revert as a hint to pin the editor this.editorGroupService.getGroup(groupId)?.pinEditor(editor); - return editor.revert(options); + return editor.revert(groupId, options); })); return result.every(success => !!success); diff --git a/src/vs/workbench/services/editor/test/browser/editorService.test.ts b/src/vs/workbench/services/editor/test/browser/editorService.test.ts index 041ae8729b85298561e4c08548f8915ee494ab1f..3e2fe4b515ac6fc9274997a09392734d4794071a 100644 --- a/src/vs/workbench/services/editor/test/browser/editorService.test.ts +++ b/src/vs/workbench/services/editor/test/browser/editorService.test.ts @@ -80,7 +80,7 @@ class TestEditorInput extends EditorInput implements IFileEditorInput { this.gotSavedAs = true; return true; } - async revert(options?: IRevertOptions): Promise { + async revert(group: GroupIdentifier, options?: IRevertOptions): Promise { this.gotReverted = true; this.gotSaved = false; this.gotSavedAs = false; diff --git a/src/vs/workbench/services/textfile/browser/textFileService.ts b/src/vs/workbench/services/textfile/browser/textFileService.ts index 3090dcfe774cb0597c3790728db5fbc06c2e0e10..5b931d9934068912cffd484ea199a3266a3ae8e9 100644 --- a/src/vs/workbench/services/textfile/browser/textFileService.ts +++ b/src/vs/workbench/services/textfile/browser/textFileService.ts @@ -579,7 +579,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex if (resource.scheme === Schemas.untitled) { const model = this.untitled.get(resource); if (model) { - return model.revert(options); + return model.revert(0, options); } return false; diff --git a/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts b/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts index c5b76cba3b2bc1c231025b1f47fe46fcd37c659c..3d0d97cfd4821ad8223d9c01e961a02e7b927b96 100644 --- a/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts +++ b/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts @@ -62,7 +62,7 @@ suite('Workbench untitled text editors', () => { assert.equal(service.get(input2.getResource()), input2); // revert() - input1.revert(); + input1.revert(0); assert.ok(input1.isDisposed()); assert.ok(!service.get(input1.getResource())); @@ -82,8 +82,8 @@ suite('Workbench untitled text editors', () => { assert.ok(workingCopyService.isDirty(input2.getResource())); assert.equal(workingCopyService.dirtyCount, 1); - input1.revert(); - input2.revert(); + input1.revert(0); + input2.revert(0); assert.ok(!service.get(input1.getResource())); assert.ok(!service.get(input2.getResource())); assert.ok(!input2.isDirty()); @@ -92,7 +92,7 @@ suite('Workbench untitled text editors', () => { assert.ok(!workingCopyService.isDirty(input2.getResource())); assert.equal(workingCopyService.dirtyCount, 0); - assert.ok(input1.revert()); + assert.ok(input1.revert(0)); assert.ok(input1.isDisposed()); assert.ok(!service.exists(input1.getResource()));