diff --git a/src/vs/workbench/common/editor/untitledEditorInput.ts b/src/vs/workbench/common/editor/untitledEditorInput.ts index 280db81da30..46f6b45d23d 100644 --- a/src/vs/workbench/common/editor/untitledEditorInput.ts +++ b/src/vs/workbench/common/editor/untitledEditorInput.ts @@ -18,7 +18,7 @@ import { IModeService } from 'vs/editor/common/services/modeService'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import Event, { Emitter } from 'vs/base/common/event'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; -import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; +import { IBackupFileService, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup'; /** * An editor input to be used for untitled text buffers. @@ -161,7 +161,7 @@ export class UntitledEditorInput extends AbstractUntitledEditorInput { if (hasBackup) { const restoreResource = this.backupFileService.getBackupResource(this.resource); - return this.textFileService.resolveTextContent(restoreResource).then(rawTextContent => rawTextContent.value.lines.join('\n')); + return this.textFileService.resolveTextContent(restoreResource, BACKUP_FILE_RESOLVE_OPTIONS).then(rawTextContent => rawTextContent.value.lines.join('\n')); } return ''; diff --git a/src/vs/workbench/services/backup/common/backup.ts b/src/vs/workbench/services/backup/common/backup.ts index 029dcfb0b6a..5d438f8ec48 100644 --- a/src/vs/workbench/services/backup/common/backup.ts +++ b/src/vs/workbench/services/backup/common/backup.ts @@ -9,10 +9,14 @@ import Uri from 'vs/base/common/uri'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { TPromise } from 'vs/base/common/winjs.base'; import { ITextFileEditorModelManager } from 'vs/workbench/services/textfile/common/textfiles'; +import { IResolveContentOptions, IUpdateContentOptions } from 'vs/platform/files/common/files'; export const IBackupService = createDecorator('backupService'); export const IBackupFileService = createDecorator('backupFileService'); +export const BACKUP_FILE_RESOLVE_OPTIONS: IResolveContentOptions = { acceptTextOnly: true, encoding: 'utf-8' }; +export const BACKUP_FILE_UPDATE_OPTIONS: IUpdateContentOptions = { encoding: 'utf-8' }; + export interface IBackupResult { didBackup: boolean; } diff --git a/src/vs/workbench/services/backup/node/backupFileService.ts b/src/vs/workbench/services/backup/node/backupFileService.ts index 230c09cde84..7b372b99eb6 100644 --- a/src/vs/workbench/services/backup/node/backupFileService.ts +++ b/src/vs/workbench/services/backup/node/backupFileService.ts @@ -10,7 +10,7 @@ import * as crypto from 'crypto'; import pfs = require('vs/base/node/pfs'); import Uri from 'vs/base/common/uri'; import { IBackupWorkspacesFormat } from 'vs/platform/backup/common/backup'; -import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; +import { IBackupFileService, BACKUP_FILE_UPDATE_OPTIONS } from 'vs/workbench/services/backup/common/backup'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { IFileService } from 'vs/platform/files/common/files'; import { TPromise } from 'vs/base/common/winjs.base'; @@ -78,7 +78,7 @@ export class BackupFileService implements IBackupFileService { return TPromise.as(void 0); } - return this.fileService.updateContent(backupResource, content).then(() => void 0); + return this.fileService.updateContent(backupResource, content, BACKUP_FILE_UPDATE_OPTIONS).then(() => void 0); } public discardResourceBackup(resource: Uri): TPromise { diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index 8e8b3f96617..9500cc52528 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -22,7 +22,7 @@ import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { ITextFileService, IAutoSaveConfiguration, ModelState, ITextFileEditorModel, IModelSaveOptions, ISaveErrorHandler, ISaveParticipant, StateChange, SaveReason } from 'vs/workbench/services/textfile/common/textfiles'; import { EncodingMode, EditorModel } from 'vs/workbench/common/editor'; import { BaseTextEditorModel } from 'vs/workbench/common/editor/textEditorModel'; -import { IBackupFileService } from 'vs/workbench/services/backup/common/backup'; +import { IBackupFileService, BACKUP_FILE_RESOLVE_OPTIONS } from 'vs/workbench/services/backup/common/backup'; import { IFileService, IFileStat, IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IMessageService, Severity } from 'vs/platform/message/common/message'; @@ -287,9 +287,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil // Try get restore content, if there is an issue fallback silently to the original file's content if (backupExists) { const restoreResource = this.backupFileService.getBackupResource(this.resource); - const restoreOptions = { acceptTextOnly: true, encoding: 'utf-8' }; - - resolveBackupPromise = this.textFileService.resolveTextContent(restoreResource, restoreOptions).then(backup => backup.value, error => content.value); + resolveBackupPromise = this.textFileService.resolveTextContent(restoreResource, BACKUP_FILE_RESOLVE_OPTIONS).then(backup => backup.value, error => content.value); } else { resolveBackupPromise = TPromise.as(content.value); }