@@ -17,7 +17,7 @@ import 'vs/css!./media/mergeEditor';
17
17
import { ICodeEditor } from 'vs/editor/browser/editorBrowser' ;
18
18
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget' ;
19
19
import { IEditorOptions as ICodeEditorOptions } from 'vs/editor/common/config/editorOptions' ;
20
- import { ScrollType } from 'vs/editor/common/editorCommon' ;
20
+ import { ICodeEditorViewState , ScrollType } from 'vs/editor/common/editorCommon' ;
21
21
import { ITextResourceConfigurationService } from 'vs/editor/common/services/textResourceConfiguration' ;
22
22
import { localize } from 'vs/nls' ;
23
23
import { createAndFillInActionBarActions } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
@@ -83,7 +83,7 @@ class MergeEditorLayout {
83
83
}
84
84
}
85
85
86
- export class MergeEditor extends AbstractTextEditor < any > {
86
+ export class MergeEditor extends AbstractTextEditor < IMergeEditorViewState > {
87
87
88
88
static readonly ID = 'mergeEditor' ;
89
89
@@ -282,6 +282,9 @@ export class MergeEditor extends AbstractTextEditor<any> {
282
282
this . inputResultView . setModel ( viewModel , model . result , localize ( 'result' , 'Result' , ) , this . _labelService . getUriLabel ( model . result . uri , { relative : true } ) , undefined ) ;
283
283
this . _ctxBaseResourceScheme . set ( model . base . uri . scheme ) ;
284
284
285
+ const viewState = this . loadEditorViewState ( input , context ) ;
286
+ this . _applyViewState ( viewState ) ;
287
+
285
288
this . _sessionDisposables . add ( thenIfNotDisposed ( model . onInitialized , ( ) => {
286
289
const firstConflict = model . modifiedBaseRanges . get ( ) . find ( r => r . isConflicting ) ;
287
290
if ( ! firstConflict ) {
@@ -439,17 +442,50 @@ export class MergeEditor extends AbstractTextEditor<any> {
439
442
this . _ctxUsesColumnLayout . set ( newValue ) ;
440
443
}
441
444
442
- // --- view state (TODO@bpasero revisit with https://github.com/microsoft/vscode/issues/150804)
445
+ private _applyViewState ( state : IMergeEditorViewState | undefined ) {
446
+ if ( ! state ) {
447
+ return ;
448
+ }
449
+ this . inputResultView . editor . restoreViewState ( state ) ;
450
+ if ( state . input1State ) {
451
+ this . input1View . editor . restoreViewState ( state . input1State ) ;
452
+ }
453
+ if ( state . input2State ) {
454
+ this . input2View . editor . restoreViewState ( state . input2State ) ;
455
+ }
456
+ if ( state . focusIndex >= 0 ) {
457
+ [ this . input1View . editor , this . input2View . editor , this . inputResultView . editor ] [ state . focusIndex ] . focus ( ) ;
458
+ }
459
+ }
443
460
444
- protected computeEditorViewState ( resource : URI ) : undefined {
445
- return undefined ;
461
+ protected computeEditorViewState ( resource : URI ) : IMergeEditorViewState | undefined {
462
+ if ( isEqual ( this . model ?. result . uri , resource ) ) {
463
+ // TODO@bpasero Why not check `input#resource` and don't ask me for "forgein" resources?
464
+ return undefined ;
465
+ }
466
+ const result = this . inputResultView . editor . saveViewState ( ) ;
467
+ if ( ! result ) {
468
+ return undefined ;
469
+ }
470
+ const input1State = this . input1View . editor . saveViewState ( ) ?? undefined ;
471
+ const input2State = this . input2View . editor . saveViewState ( ) ?? undefined ;
472
+ const focusIndex = [ this . input1View . editor , this . input2View . editor , this . inputResultView . editor ] . findIndex ( editor => editor . hasWidgetFocus ( ) ) ;
473
+ return { ...result , input1State, input2State, focusIndex } ;
446
474
}
447
475
476
+
448
477
protected tracksEditorViewState ( input : EditorInput ) : boolean {
449
- return false ;
478
+ return input instanceof MergeEditorInput ;
450
479
}
451
480
}
452
481
482
+ type IMergeEditorViewState = ICodeEditorViewState & {
483
+ readonly input1State ?: ICodeEditorViewState ;
484
+ readonly input2State ?: ICodeEditorViewState ;
485
+ readonly focusIndex : number ;
486
+ } ;
487
+
488
+
453
489
function synchronizeScrolling ( scrollingEditor : CodeEditorWidget , targetEditor : CodeEditorWidget , mapping : DocumentMapping | undefined , source : MappingDirection ) {
454
490
if ( ! mapping ) {
455
491
return ;
0 commit comments