@@ -11,12 +11,13 @@ import { CancellationToken } from 'vs/base/common/cancellation';
11
11
import { Color } from 'vs/base/common/color' ;
12
12
import { BugIndicatingError } from 'vs/base/common/errors' ;
13
13
import { Emitter , Event } from 'vs/base/common/event' ;
14
- import { DisposableStore , MutableDisposable } from 'vs/base/common/lifecycle' ;
14
+ import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
15
15
import { autorunWithStore , IObservable } from 'vs/base/common/observable' ;
16
16
import { isEqual } from 'vs/base/common/resources' ;
17
17
import { URI } from 'vs/base/common/uri' ;
18
18
import 'vs/css!./media/mergeEditor' ;
19
19
import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
20
+ import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService' ;
20
21
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget' ;
21
22
import { IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions' ;
22
23
import { ICodeEditorViewState , ScrollType } from 'vs/editor/common/editorCommon' ;
@@ -26,7 +27,7 @@ import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/men
26
27
import { IMenuService , MenuId } from 'vs/platform/actions/common/actions' ;
27
28
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
28
29
import { IContextKey , IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
29
- import { IEditorOptions , ITextEditorOptions } from 'vs/platform/editor/common/editor' ;
30
+ import { IEditorOptions , ITextEditorOptions , ITextResourceEditorInput } from 'vs/platform/editor/common/editor' ;
30
31
import { IFileService } from 'vs/platform/files/common/files' ;
31
32
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
32
33
import { ILabelService } from 'vs/platform/label/common/label' ;
@@ -35,7 +36,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
35
36
import { IThemeService } from 'vs/platform/theme/common/themeService' ;
36
37
import { FloatingClickWidget } from 'vs/workbench/browser/codeeditor' ;
37
38
import { AbstractTextEditor } from 'vs/workbench/browser/parts/editor/textEditor' ;
38
- import { EditorInputWithOptions , EditorResourceAccessor , IEditorOpenContext } from 'vs/workbench/common/editor' ;
39
+ import { IEditorOpenContext } from 'vs/workbench/common/editor' ;
39
40
import { EditorInput } from 'vs/workbench/common/editor/editorInput' ;
40
41
import { applyTextEditorOptions } from 'vs/workbench/common/editor/editorOptions' ;
41
42
import { MergeEditorInput } from 'vs/workbench/contrib/mergeEditor/browser/mergeEditorInput' ;
@@ -46,7 +47,6 @@ import { MergeEditorViewModel } from 'vs/workbench/contrib/mergeEditor/browser/v
46
47
import { ctxBaseResourceScheme , ctxIsMergeEditor , ctxMergeEditorLayout , MergeEditorLayoutTypes } from 'vs/workbench/contrib/mergeEditor/common/mergeEditor' ;
47
48
import { settingsSashBorder } from 'vs/workbench/contrib/preferences/common/settingsEditorColorRegistry' ;
48
49
import { IEditorGroup , IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService' ;
49
- import { IEditorResolverService , RegisteredEditorPriority } from 'vs/workbench/services/editor/common/editorResolverService' ;
50
50
import { IEditorService } from 'vs/workbench/services/editor/common/editorService' ;
51
51
import './colors' ;
52
52
import { InputCodeEditorView } from './editors/inputCodeEditorView' ;
@@ -86,9 +86,9 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
86
86
private readonly _sessionDisposables = new DisposableStore ( ) ;
87
87
88
88
private _grid ! : Grid < IView > ;
89
- private readonly input1View = this . _register ( this . instantiation . createInstance ( InputCodeEditorView , 1 ) ) ;
90
- private readonly input2View = this . _register ( this . instantiation . createInstance ( InputCodeEditorView , 2 ) ) ;
91
- private readonly inputResultView = this . _register ( this . instantiation . createInstance ( ResultCodeEditorView ) ) ;
89
+ private readonly input1View = this . _register ( this . instantiationService . createInstance ( InputCodeEditorView , 1 ) ) ;
90
+ private readonly input2View = this . _register ( this . instantiationService . createInstance ( InputCodeEditorView , 2 ) ) ;
91
+ private readonly inputResultView = this . _register ( this . instantiationService . createInstance ( ResultCodeEditorView ) ) ;
92
92
93
93
private readonly _layoutMode : MergeEditorLayout ;
94
94
private readonly _ctxIsMergeEditor : IContextKey < boolean > ;
@@ -103,7 +103,7 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
103
103
}
104
104
105
105
constructor (
106
- @IInstantiationService private readonly instantiation : IInstantiationService ,
106
+ @IInstantiationService instantiation : IInstantiationService ,
107
107
@ILabelService private readonly _labelService : ILabelService ,
108
108
@IMenuService private readonly _menuService : IMenuService ,
109
109
@IContextKeyService private readonly _contextKeyService : IContextKeyService ,
@@ -115,7 +115,6 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
115
115
@IEditorService editorService : IEditorService ,
116
116
@IEditorGroupsService editorGroupService : IEditorGroupsService ,
117
117
@IFileService fileService : IFileService ,
118
- @IEditorResolverService private readonly _editorResolverService : IEditorResolverService ,
119
118
) {
120
119
super ( MergeEditor . ID , telemetryService , instantiation , storageService , textResourceConfigurationService , themeService , editorService , editorGroupService , fileService ) ;
121
120
@@ -186,7 +185,7 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
186
185
createAndFillInActionBarActions ( toolbarMenu , { renderShortTitle : true , shouldForwardArgs : true } , actions ) ;
187
186
if ( actions . length > 0 ) {
188
187
const [ first ] = actions ;
189
- const acceptBtn = this . instantiation . createInstance ( FloatingClickWidget , this . inputResultView . editor , first . label , first . id ) ;
188
+ const acceptBtn = this . instantiationService . createInstance ( FloatingClickWidget , this . inputResultView . editor , first . label , first . id ) ;
190
189
toolbarMenuDisposables . add ( acceptBtn . onClick ( ( ) => first . run ( this . inputResultView . editor . getModel ( ) ?. uri ) ) ) ;
191
190
toolbarMenuDisposables . add ( acceptBtn ) ;
192
191
acceptBtn . render ( ) ;
@@ -296,7 +295,6 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
296
295
await super . setInput ( input , options , context , token ) ;
297
296
298
297
this . _sessionDisposables . clear ( ) ;
299
- this . _toggleEditorOverwrite ( true ) ;
300
298
301
299
const model = await input . resolve ( ) ;
302
300
this . _model = model ;
@@ -373,7 +371,6 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
373
371
super . clearInput ( ) ;
374
372
375
373
this . _sessionDisposables . clear ( ) ;
376
- this . _toggleEditorOverwrite ( false ) ;
377
374
378
375
for ( const { editor } of [ this . input1View , this . input2View , this . inputResultView ] ) {
379
376
editor . setModel ( null ) ;
@@ -405,39 +402,6 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
405
402
}
406
403
407
404
this . _ctxIsMergeEditor . set ( visible ) ;
408
- this . _toggleEditorOverwrite ( visible ) ;
409
- }
410
-
411
- private readonly _editorOverrideHandle = this . _store . add ( new MutableDisposable ( ) ) ;
412
-
413
- private _toggleEditorOverwrite ( haveIt : boolean ) {
414
- if ( ! haveIt ) {
415
- this . _editorOverrideHandle . clear ( ) ;
416
- return ;
417
- }
418
- // this is RATHER UGLY. I dynamically register an editor for THIS (editor,input) so that
419
- // navigating within the merge editor works, e.g navigating from the outline or breakcrumps
420
- // or revealing a definition, reference etc
421
- // TODO@jrieken @bpasero @lramos 15
422
- const input = this . input ;
423
- if ( input instanceof MergeEditorInput ) {
424
- this . _editorOverrideHandle . value = this . _editorResolverService . registerEditor (
425
- `${ input . result . scheme } :${ input . result . fsPath } ` ,
426
- {
427
- id : `${ this . getId ( ) } /fake` ,
428
- label : this . input ?. getName ( ) ! ,
429
- priority : RegisteredEditorPriority . exclusive
430
- } ,
431
- { } ,
432
- ( candidate ) : EditorInputWithOptions => {
433
- const resource = EditorResourceAccessor . getCanonicalUri ( candidate ) ;
434
- if ( ! isEqual ( resource , this . model ?. result . uri ) ) {
435
- throw new Error ( `Expected to be called WITH ${ input . result . toString ( ) } ` ) ;
436
- }
437
- return { editor : input } ;
438
- }
439
- ) ;
440
- }
441
405
}
442
406
443
407
// ---- interact with "outside world" via`getControl`, `scopedContextKeyService`: we only expose the result-editor keep the others internal
@@ -506,6 +470,37 @@ export class MergeEditor extends AbstractTextEditor<IMergeEditorViewState> {
506
470
}
507
471
}
508
472
473
+ export class MergeEditorOpenHandlerContribution extends Disposable {
474
+
475
+ constructor (
476
+ @IEditorService private readonly _editorService : IEditorService ,
477
+ @ICodeEditorService codeEditorService : ICodeEditorService ,
478
+ ) {
479
+ super ( ) ;
480
+ this . _store . add ( codeEditorService . registerCodeEditorOpenHandler ( this . openCodeEditorFromMergeEditor . bind ( this ) ) ) ;
481
+ }
482
+
483
+ private async openCodeEditorFromMergeEditor ( input : ITextResourceEditorInput , _source : ICodeEditor | null , sideBySide ?: boolean | undefined ) : Promise < ICodeEditor | null > {
484
+ const activePane = this . _editorService . activeEditorPane ;
485
+ if ( ! sideBySide
486
+ && input . options
487
+ && activePane instanceof MergeEditor
488
+ && activePane . getControl ( )
489
+ && activePane . input instanceof MergeEditorInput
490
+ && isEqual ( input . resource , activePane . input . result )
491
+ ) {
492
+ // Special: stay inside the merge editor when it is active and when the input
493
+ // targets the result editor of the merge editor.
494
+ const targetEditor = < ICodeEditor > activePane . getControl ( ) ! ;
495
+ applyTextEditorOptions ( input . options , targetEditor , ScrollType . Smooth ) ;
496
+ return targetEditor ;
497
+ }
498
+
499
+ // cannot handle this
500
+ return null ;
501
+ }
502
+ }
503
+
509
504
type IMergeEditorViewState = ICodeEditorViewState & {
510
505
readonly input1State ?: ICodeEditorViewState ;
511
506
readonly input2State ?: ICodeEditorViewState ;
0 commit comments