Skip to content

Commit

Permalink
Preserve language picked for untitled text documents (fixes #16803)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Dec 13, 2016
1 parent 804096b commit 122d3a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/vs/workbench/browser/parts/editor/editor.contribution.ts
Expand Up @@ -96,6 +96,7 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(

interface ISerializedUntitledEditorInput {
resource: string;
modeId: string;
}

// Register Editor Input Factory
Expand All @@ -119,15 +120,15 @@ 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);
}

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);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/vs/workbench/common/editor/untitledEditorInput.ts
Expand Up @@ -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;
}
Expand Down

0 comments on commit 122d3a6

Please sign in to comment.