From 8887fe1eacee0131ce28a6254ee3371a74b40f37 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Tue, 11 Sep 2018 17:06:28 -0700 Subject: [PATCH] fix the save and save all for untitled file (#2526) --- .../files/electron-browser/fileCommands.ts | 21 +++++++++++++++---- .../services/editor/browser/editorService.ts | 17 ++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts index e6c4bafff5..7028a9aacd 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileCommands.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileCommands.ts @@ -40,7 +40,7 @@ import { getMultiSelectedEditorContexts } from 'vs/workbench/browser/parts/edito import { Schemas } from 'vs/base/common/network'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { EditorContextKeys } from 'vs/editor/common/editorContextKeys'; -import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService'; +import { IEditorService, SIDE_GROUP, IResourceEditorReplacement } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; import { isEqual, basenameOrAuthority } from 'vs/base/common/resources'; import { ltrim } from 'vs/base/common/strings'; @@ -165,7 +165,7 @@ function save( // {{SQL CARBON EDIT}} queryEditorService.onSaveAsCompleted(resource, target); return true; - }); + }); }); } @@ -215,14 +215,27 @@ function saveAll(saveAllArguments: any, editorService: IEditorService, untitledE // Save all return textFileService.saveAll(saveAllArguments).then((result) => { groupIdToUntitledResourceInput.forEach((inputs, groupId) => { + // {{SQL CARBON EDIT}} // Update untitled resources to the saved ones, so we open the proper files + + let replacementPairs: IResourceEditorReplacement[] = []; inputs.forEach(i => { const targetResult = result.results.filter(r => r.success && r.source.toString() === i.resource.toString()).pop(); if (targetResult) { - i.resource = targetResult.target; + //i.resource = targetResult.target; + let editor = i; + const replacement: IResourceInput = { + resource: targetResult.target, + encoding: i.encoding, + options: { + pinned: true, + viewState: undefined + } + }; + replacementPairs.push({ editor: editor, replacement: replacement }); } }); - editorService.openEditors(inputs, groupId); + editorService.replaceEditors(replacementPairs, groupId); }); }); } diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 4303da43fd..71fe3d0b99 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -233,18 +233,12 @@ export class EditorService extends Disposable implements EditorServiceImpl { return this.doOpenEditor(targetGroup, editor, editorOptions); } - // {{SQL CARBON EDIT}} // Untyped Text Editor Support const textInput = editor; - let typedInput = this.createInput(textInput); + const typedInput = this.createInput(textInput); if (typedInput) { const editorOptions = TextEditorOptions.from(textInput); const targetGroup = this.findTargetGroup(typedInput, editorOptions, optionsOrGroup as IEditorGroup | GroupIdentifier); - - // {{SQL CARBON EDIT}} - // Convert input into custom type if it's one of the ones we support - typedInput = convertEditorInput(typedInput, editorOptions, this.instantiationService); - return this.doOpenEditor(targetGroup, typedInput, editorOptions); } @@ -501,12 +495,12 @@ export class EditorService extends Disposable implements EditorServiceImpl { const untitledInput = input; if (!untitledInput.resource || typeof untitledInput.filePath === 'string' || (untitledInput.resource instanceof URI && untitledInput.resource.scheme === Schemas.untitled)) { // {{SQL CARBON EDIT}} - return this.untitledEditorService.createOrGet( + return convertEditorInput(this.untitledEditorService.createOrGet( untitledInput.filePath ? URI.file(untitledInput.filePath) : untitledInput.resource, 'sql', untitledInput.contents, untitledInput.encoding - ); + ), undefined, this.instantiationService); } // Resource Editor Support @@ -516,8 +510,9 @@ export class EditorService extends Disposable implements EditorServiceImpl { if (!label && resourceInput.resource.scheme !== Schemas.data) { label = basename(resourceInput.resource.fsPath); // derive the label from the path (but not for data URIs) } - - return this.createOrGet(resourceInput.resource, this.instantiationService, label, resourceInput.description, resourceInput.encoding, options && options.forceFileInput) as EditorInput; + // {{SQL CARBON EDIT}} + return convertEditorInput(this.createOrGet(resourceInput.resource, this.instantiationService, label, resourceInput.description, resourceInput.encoding, options && options.forceFileInput) as EditorInput, + undefined, this.instantiationService); } return null;