diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index d1b42b2ba89..e2f4738ba10 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -749,11 +749,13 @@ export function getUntitledOrFileResource(input: IEditorInput, supportDiff?: boo // File let fileInput = asFileEditorInput(input, supportDiff); - return fileInput && fileInput && fileInput.getResource(); + + return fileInput && fileInput.getResource(); } +// TODO@Ben every editor should have an associated resource export function getResource(input: IEditorInput): URI { - if (input && typeof (input).getResource === 'function') { + if (input instanceof EditorInput && typeof (input).getResource === 'function') { let candidate = (input).getResource(); if (candidate instanceof URI) { return candidate; diff --git a/src/vs/workbench/test/common/editor/editorStacksModel.test.ts b/src/vs/workbench/test/common/editor/editorStacksModel.test.ts index 11cce814aa3..a529a78850d 100644 --- a/src/vs/workbench/test/common/editor/editorStacksModel.test.ts +++ b/src/vs/workbench/test/common/editor/editorStacksModel.test.ts @@ -111,6 +111,10 @@ class TestEditorInput extends EditorInput { public setDirty(): void { this._onDidChangeDirty.fire(); } + + public setLabel(): void { + this._onDidChangeLabel.fire(); + } } class NonSerializableTestEditorInput extends EditorInput { @@ -1641,7 +1645,7 @@ suite('Editor Stacks Model', () => { assert.equal(input1.isDisposed(), false); }); - test('Stack - Multiple Editors - Editor Emits Dirty', function () { + test('Stack - Multiple Editors - Editor Emits Dirty and Label Changed', function () { const model = create(); const group1 = model.openGroup('group1'); @@ -1658,25 +1662,38 @@ suite('Editor Stacks Model', () => { dirtyCounter++; }); + let labelChangeCounter = 0; + model.onEditorLabelChange(() => { + labelChangeCounter++; + }); + (input1).setDirty(); + (input1).setLabel(); assert.equal(dirtyCounter, 1); + assert.equal(labelChangeCounter, 1); (input2).setDirty(); + (input2).setLabel(); assert.equal(dirtyCounter, 2); + assert.equal(labelChangeCounter, 2); group2.closeAllEditors(); (input2).setDirty(); + (input2).setLabel(); assert.equal(dirtyCounter, 2); + assert.equal(labelChangeCounter, 2); model.closeGroups(); (input1).setDirty(); + (input1).setLabel(); assert.equal(dirtyCounter, 2); + assert.equal(labelChangeCounter, 2); }); test('Groups - Model change events (structural vs state)', function () {