From 122d3a61c34147682f742e92d93ebe2168a6a3b0 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 13 Dec 2016 12:55:14 +0100 Subject: [PATCH] Preserve language picked for untitled text documents (fixes #16803) --- .../workbench/browser/parts/editor/editor.contribution.ts | 5 +++-- src/vs/workbench/common/editor/untitledEditorInput.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index c45244baa59a2..112e11ffdb2d9 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -96,6 +96,7 @@ Registry.as(EditorExtensions.Editors).registerEditor( interface ISerializedUntitledEditorInput { resource: string; + modeId: string; } // Register Editor Input Factory @@ -119,7 +120,7 @@ class UntitledEditorInputFactory implements IEditorInputFactory { resource = URI.file(resource.fsPath); // untitled with associated file path use the file schema } - const serialized: ISerializedUntitledEditorInput = { resource: resource.toString() }; + const serialized: ISerializedUntitledEditorInput = { resource: resource.toString(), modeId: untitledEditorInput.getModeId() }; return JSON.stringify(serialized); } @@ -127,7 +128,7 @@ class UntitledEditorInputFactory implements IEditorInputFactory { public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput { const deserialized: ISerializedUntitledEditorInput = JSON.parse(serializedEditorInput); - return this.untitledEditorService.createOrGet(URI.parse(deserialized.resource)); + return this.untitledEditorService.createOrGet(URI.parse(deserialized.resource), deserialized.modeId); } } diff --git a/src/vs/workbench/common/editor/untitledEditorInput.ts b/src/vs/workbench/common/editor/untitledEditorInput.ts index b0b06119b782a..9deda9eabab4d 100644 --- a/src/vs/workbench/common/editor/untitledEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledEditorInput.ts @@ -75,6 +75,14 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { return this.resource; } + public getModeId(): string { + if (this.cachedModel) { + return this.cachedModel.getModeId(); + } + + return this.modeId; + } + public getName(): string { return this.hasAssociatedFilePath ? paths.basename(this.resource.fsPath) : this.resource.fsPath; }