From 25a1117781a7e7048ff1b00e91486951f6264d26 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sat, 26 May 2018 08:43:57 +0200 Subject: [PATCH] grid -never instantiate child code editor service --- .../browser/parts/editor/textDiffEditor.ts | 43 ++----------------- .../codeEditor/browser/codeEditorService.ts | 28 ++++++++++++ 2 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts index 9a38c877e68..6e2521d9bab 100644 --- a/src/vs/workbench/browser/parts/editor/textDiffEditor.ts +++ b/src/vs/workbench/browser/parts/editor/textDiffEditor.ts @@ -11,7 +11,7 @@ import * as nls from 'vs/nls'; import * as objects from 'vs/base/common/objects'; import { Action, IAction } from 'vs/base/common/actions'; import * as types from 'vs/base/common/types'; -import { IDiffEditor, ICodeEditor } from 'vs/editor/browser/editorBrowser'; +import { IDiffEditor } from 'vs/editor/browser/editorBrowser'; import { IDiffEditorOptions, IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions'; import { BaseTextEditor, IEditorConfiguration } from 'vs/workbench/browser/parts/editor/textEditor'; import { TextEditorOptions, EditorInput, EditorOptions, TEXT_DIFF_EDITOR_ID, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions, ITextDiffEditor } from 'vs/workbench/common/editor'; @@ -25,7 +25,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IStorageService } from 'vs/platform/storage/common/storage'; import { ITextResourceConfigurationService } from 'vs/editor/common/services/resourceConfiguration'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; -import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ScrollType, IDiffEditorViewState, IDiffEditorModel } from 'vs/editor/common/editorCommon'; @@ -34,12 +33,9 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { Registry } from 'vs/platform/registry/common/platform'; import URI from 'vs/base/common/uri'; import { once } from 'vs/base/common/event'; -import { DelegatingWorkbenchEditorService } from 'vs/workbench/services/editor/browser/editorService'; -import { IEditorGroup, IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; +import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { CancellationToken } from 'vs/base/common/cancellation'; -import { CodeEditorService } from 'vs/workbench/services/codeEditor/browser/codeEditorService'; -import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'; /** * The text editor that leverages the diff text editor for the editing experience. @@ -91,40 +87,7 @@ export class TextDiffEditor extends BaseTextEditor implements ITextDiffEditor { this.toggleIgnoreTrimWhitespaceAction = new ToggleIgnoreTrimWhitespaceAction(this._actualConfigurationService); this.updateIgnoreTrimWhitespaceAction(); - // Support navigation within the diff editor by overriding the editor service within - const delegatingEditorService = this.instantiationService.createInstance(DelegatingWorkbenchEditorService); - delegatingEditorService.setEditorOpenHandler((group: IEditorGroup, input: EditorInput, options?: EditorOptions) => { - const activeDiffInput = this.input; - - // Check if target group is same as this editor ones - if (group === this.group && input && activeDiffInput && options instanceof TextEditorOptions) { - - // Find out if input matches any of both sides - let targetEditor: ICodeEditor; - if (input.matches(activeDiffInput.modifiedInput)) { - targetEditor = this.getControl().getModifiedEditor(); - } else if (input.matches(activeDiffInput.originalInput)) { - targetEditor = this.getControl().getOriginalEditor(); - } - - // Apply if possible - if (targetEditor) { - options.apply(targetEditor, ScrollType.Smooth); - - return TPromise.as(this); - } - } - - return TPromise.as(null); - }); - - // Create a special child of instantiator that will delegate all calls to openEditor() to the same diff editor if the input matches with the modified one - const diffEditorInstantiator = this.instantiationService.createChild(new ServiceCollection( - [IEditorService, delegatingEditorService], - [ICodeEditorService, new CodeEditorService(delegatingEditorService, this.themeService)] - )); - - return diffEditorInstantiator.createInstance(DiffEditorWidget, parent, configuration); + return this.instantiationService.createInstance(DiffEditorWidget, parent, configuration); } public setInput(input: EditorInput, options: EditorOptions, token: CancellationToken): Thenable { diff --git a/src/vs/workbench/services/codeEditor/browser/codeEditorService.ts b/src/vs/workbench/services/codeEditor/browser/codeEditorService.ts index d3276328793..046339582fa 100644 --- a/src/vs/workbench/services/codeEditor/browser/codeEditorService.ts +++ b/src/vs/workbench/services/codeEditor/browser/codeEditorService.ts @@ -11,6 +11,8 @@ import { IResourceInput } from 'vs/platform/editor/common/editor'; import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { TPromise } from 'vs/base/common/winjs.base'; +import { TextEditorOptions } from '../../../common/editor'; +import { ScrollType } from 'vs/editor/common/editorCommon'; export class CodeEditorService extends CodeEditorServiceImpl { @@ -35,6 +37,32 @@ export class CodeEditorService extends CodeEditorServiceImpl { } openCodeEditor(input: IResourceInput, source: ICodeEditor, sideBySide?: boolean): TPromise { + + // Special case: If the active editor is a diff editor and the request to open originates and + // targets the modified side of it, we just apply the request there to prevent opening the modified + // side as separate editor. + const activeTextEditorWidget = this.editorService.activeTextEditorWidget; + if ( + input.resource && // we need a resource to compare with + input.options && // we need options to apply + !sideBySide && // we need the current active group to be the taret + isDiffEditor(activeTextEditorWidget) && // we only support this for active text diff editors + source === activeTextEditorWidget.getModifiedEditor() && // we need the source of this request to be the modified side of the diff editor + input.resource.toString() === activeTextEditorWidget.getModel().modified.uri.toString() // we need the input resources to match with modified side + ) { + const targetEditor = activeTextEditorWidget.getModifiedEditor(); + + const textOptions = TextEditorOptions.create(input.options); + textOptions.apply(targetEditor, ScrollType.Smooth); + + return TPromise.as(targetEditor); + } + + // Open using our normal editor service + return this.doOpenCodeEditor(input, source, sideBySide); + } + + private doOpenCodeEditor(input: IResourceInput, source: ICodeEditor, sideBySide?: boolean): TPromise { return this.editorService.openEditor(input, sideBySide ? SIDE_GROUP : ACTIVE_GROUP).then(control => { if (control) { const widget = control.getControl(); -- GitLab