diff options
Diffstat (limited to 'src/vs/workbench/services/editor/browser/editorService.ts')
-rw-r--r-- | src/vs/workbench/services/editor/browser/editorService.ts | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index c31eab43d77..4a2b8ea5e9d 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -5,10 +5,10 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { IResourceEditorInput, IEditorOptions, EditorActivation, EditorResolution, IResourceEditorInputIdentifier, ITextResourceEditorInput } from 'vs/platform/editor/common/editor'; -import { SideBySideEditor, IEditorPane, GroupIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, EditorInputWithOptions, isEditorInputWithOptions, IEditorIdentifier, IEditorCloseEvent, ITextDiffEditorPane, IRevertOptions, SaveReason, EditorsOrder, IWorkbenchEditorConfiguration, EditorResourceAccessor, IVisibleEditorPane, EditorInputCapabilities, isResourceDiffEditorInput, IUntypedEditorInput, isResourceEditorInput, isEditorInput, isEditorInputWithOptionsAndGroup, IFindEditorOptions } from 'vs/workbench/common/editor'; +import { SideBySideEditor, IEditorPane, GroupIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, EditorInputWithOptions, isEditorInputWithOptions, IEditorIdentifier, IEditorCloseEvent, ITextDiffEditorPane, IRevertOptions, SaveReason, EditorsOrder, IWorkbenchEditorConfiguration, EditorResourceAccessor, IVisibleEditorPane, EditorInputCapabilities, isResourceDiffEditorInput, IUntypedEditorInput, isResourceEditorInput, isEditorInput, isEditorInputWithOptionsAndGroup, IFindEditorOptions, isResourceMergeEditorInput } from 'vs/workbench/common/editor'; import { EditorInput } from 'vs/workbench/common/editor/editorInput'; import { SideBySideEditorInput } from 'vs/workbench/common/editor/sideBySideEditorInput'; -import { ResourceMap } from 'vs/base/common/map'; +import { ResourceMap, ResourceSet } from 'vs/base/common/map'; import { IFileService, FileOperationEvent, FileOperation, FileChangesEvent, FileChangeType } from 'vs/platform/files/common/files'; import { Event, Emitter } from 'vs/base/common/event'; import { URI } from 'vs/base/common/uri'; @@ -176,7 +176,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { private readonly activeOutOfWorkspaceWatchers = new ResourceMap<IDisposable>(); private handleVisibleEditorsChange(): void { - const visibleOutOfWorkspaceResources = new ResourceMap<URI>(); + const visibleOutOfWorkspaceResources = new ResourceSet(); for (const editor of this.visibleEditors) { const resources = distinct(coalesce([ @@ -186,14 +186,14 @@ export class EditorService extends Disposable implements EditorServiceImpl { for (const resource of resources) { if (this.fileService.hasProvider(resource) && !this.contextService.isInsideWorkspace(resource)) { - visibleOutOfWorkspaceResources.set(resource, resource); + visibleOutOfWorkspaceResources.add(resource); } } } // Handle no longer visible out of workspace resources for (const resource of this.activeOutOfWorkspaceWatchers.keys()) { - if (!visibleOutOfWorkspaceResources.get(resource)) { + if (!visibleOutOfWorkspaceResources.has(resource)) { dispose(this.activeOutOfWorkspaceWatchers.get(resource)); this.activeOutOfWorkspaceWatchers.delete(resource); } @@ -605,23 +605,24 @@ export class EditorService extends Disposable implements EditorServiceImpl { } private async handleWorkspaceTrust(editors: Array<EditorInputWithOptions | IUntypedEditorInput>): Promise<boolean> { - const { resources, diffMode } = this.extractEditorResources(editors); + const { resources, diffMode, mergeMode } = this.extractEditorResources(editors); const trustResult = await this.workspaceTrustRequestService.requestOpenFilesTrust(resources); switch (trustResult) { case WorkspaceTrustUriResponse.Open: return true; case WorkspaceTrustUriResponse.OpenInNewWindow: - await this.hostService.openWindow(resources.map(resource => ({ fileUri: resource })), { forceNewWindow: true, diffMode }); + await this.hostService.openWindow(resources.map(resource => ({ fileUri: resource })), { forceNewWindow: true, diffMode, mergeMode }); return false; case WorkspaceTrustUriResponse.Cancel: return false; } } - private extractEditorResources(editors: Array<EditorInputWithOptions | IUntypedEditorInput>): { resources: URI[]; diffMode?: boolean } { - const resources = new ResourceMap<boolean>(); + private extractEditorResources(editors: Array<EditorInputWithOptions | IUntypedEditorInput>): { resources: URI[]; diffMode?: boolean; mergeMode?: boolean } { + const resources = new ResourceSet(); let diffMode = false; + let mergeMode = false; for (const editor of editors) { @@ -629,14 +630,14 @@ export class EditorService extends Disposable implements EditorServiceImpl { if (isEditorInputWithOptions(editor)) { const resource = EditorResourceAccessor.getOriginalUri(editor.editor, { supportSideBySide: SideBySideEditor.BOTH }); if (URI.isUri(resource)) { - resources.set(resource, true); + resources.add(resource); } else if (resource) { if (resource.primary) { - resources.set(resource.primary, true); + resources.add(resource.primary); } if (resource.secondary) { - resources.set(resource.secondary, true); + resources.add(resource.secondary); } diffMode = editor.editor instanceof DiffEditorInput; @@ -645,27 +646,44 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Untyped editor else { - if (isResourceDiffEditorInput(editor)) { - const originalResourceEditor = editor.original; - if (URI.isUri(originalResourceEditor.resource)) { - resources.set(originalResourceEditor.resource, true); + if (isResourceMergeEditorInput(editor)) { + if (URI.isUri(editor.input1)) { + resources.add(editor.input1.resource); } - const modifiedResourceEditor = editor.modified; - if (URI.isUri(modifiedResourceEditor.resource)) { - resources.set(modifiedResourceEditor.resource, true); + if (URI.isUri(editor.input2)) { + resources.add(editor.input2.resource); + } + + if (URI.isUri(editor.base)) { + resources.add(editor.base.resource); + } + + if (URI.isUri(editor.result)) { + resources.add(editor.result.resource); + } + + mergeMode = true; + } if (isResourceDiffEditorInput(editor)) { + if (URI.isUri(editor.original.resource)) { + resources.add(editor.original.resource); + } + + if (URI.isUri(editor.modified.resource)) { + resources.add(editor.modified.resource); } diffMode = true; } else if (isResourceEditorInput(editor)) { - resources.set(editor.resource, true); + resources.add(editor.resource); } } } return { resources: Array.from(resources.keys()), - diffMode + diffMode, + mergeMode }; } |