@@ -14,20 +14,22 @@ import { InputCodeEditorView } from 'vs/workbench/contrib/mergeEditor/browser/vi
14
14
import { ResultCodeEditorView } from 'vs/workbench/contrib/mergeEditor/browser/view/editors/resultCodeEditorView' ;
15
15
16
16
export class MergeEditorViewModel {
17
+ private counter = 0 ;
17
18
private readonly lastFocusedEditor = derivedObservableWithWritableCache <
18
- CodeEditorView | undefined
19
+ { view : CodeEditorView | undefined ; counter : number }
19
20
> ( 'lastFocusedEditor' , ( reader , lastValue ) => {
20
21
const editors = [
21
22
this . inputCodeEditorView1 ,
22
23
this . inputCodeEditorView2 ,
23
24
this . resultCodeEditorView ,
24
25
] ;
25
- return editors . find ( ( e ) => e . isFocused . read ( reader ) ) || lastValue ;
26
+ const view = editors . find ( ( e ) => e . isFocused . read ( reader ) ) ;
27
+ return view ? { view, counter : this . counter ++ } : lastValue || { view : undefined , counter : this . counter ++ } ;
26
28
} ) ;
27
29
28
30
private readonly manuallySetActiveModifiedBaseRange = observableValue <
29
- ModifiedBaseRange | undefined
30
- > ( 'manuallySetActiveModifiedBaseRange' , undefined ) ;
31
+ { range : ModifiedBaseRange | undefined ; counter : number }
32
+ > ( 'manuallySetActiveModifiedBaseRange' , { range : undefined , counter : 0 } ) ;
31
33
32
34
private getRange ( editor : CodeEditorView , modifiedBaseRange : ModifiedBaseRange , reader : IReader | undefined ) : LineRange {
33
35
if ( editor === this . resultCodeEditorView ) {
@@ -42,17 +44,22 @@ export class MergeEditorViewModel {
42
44
'activeModifiedBaseRange' ,
43
45
( reader ) => {
44
46
const focusedEditor = this . lastFocusedEditor . read ( reader ) ;
45
- if ( ! focusedEditor ) {
46
- return this . manuallySetActiveModifiedBaseRange . read ( reader ) ;
47
+ const manualRange = this . manuallySetActiveModifiedBaseRange . read ( reader ) ;
48
+ if ( manualRange . counter > focusedEditor . counter ) {
49
+ return manualRange . range ;
47
50
}
48
- const cursorLineNumber = focusedEditor . cursorLineNumber . read ( reader ) ;
51
+
52
+ if ( ! focusedEditor . view ) {
53
+ return ;
54
+ }
55
+ const cursorLineNumber = focusedEditor . view . cursorLineNumber . read ( reader ) ;
49
56
if ( ! cursorLineNumber ) {
50
57
return undefined ;
51
58
}
52
59
53
60
const modifiedBaseRanges = this . model . modifiedBaseRanges . read ( reader ) ;
54
61
return modifiedBaseRanges . find ( ( r ) => {
55
- const range = this . getRange ( focusedEditor , r , reader ) ;
62
+ const range = this . getRange ( focusedEditor . view ! , r , reader ) ;
56
63
return range . isEmpty
57
64
? range . startLineNumber === cursorLineNumber
58
65
: range . contains ( cursorLineNumber ) ;
@@ -72,28 +79,28 @@ export class MergeEditorViewModel {
72
79
state : ModifiedBaseRangeState ,
73
80
tx : ITransaction
74
81
) : void {
75
- this . manuallySetActiveModifiedBaseRange . set ( baseRange , tx ) ;
76
- this . lastFocusedEditor . clearCache ( tx ) ;
82
+ this . manuallySetActiveModifiedBaseRange . set ( { range : baseRange , counter : this . counter ++ } , tx ) ;
77
83
this . model . setState ( baseRange , state , true , tx ) ;
78
84
}
79
85
80
86
private goToConflict ( getModifiedBaseRange : ( editor : CodeEditorView , curLineNumber : number ) => ModifiedBaseRange | undefined ) : void {
81
- const lastFocusedEditor = this . lastFocusedEditor . get ( ) ;
82
- if ( ! lastFocusedEditor ) {
83
- return ;
87
+ let editor = this . lastFocusedEditor . get ( ) . view ;
88
+ if ( ! editor ) {
89
+ editor = this . resultCodeEditorView ;
84
90
}
85
- const curLineNumber = lastFocusedEditor . editor . getPosition ( ) ?. lineNumber ;
91
+ const curLineNumber = editor . editor . getPosition ( ) ?. lineNumber ;
86
92
if ( curLineNumber === undefined ) {
87
93
return ;
88
94
}
89
- const modifiedBaseRange = getModifiedBaseRange ( lastFocusedEditor , curLineNumber ) ;
95
+ const modifiedBaseRange = getModifiedBaseRange ( editor , curLineNumber ) ;
90
96
if ( modifiedBaseRange ) {
91
- const range = this . getRange ( lastFocusedEditor , modifiedBaseRange , undefined ) ;
92
- lastFocusedEditor . editor . setPosition ( {
97
+ const range = this . getRange ( editor , modifiedBaseRange , undefined ) ;
98
+ editor . editor . focus ( ) ;
99
+ editor . editor . setPosition ( {
93
100
lineNumber : range . startLineNumber ,
94
- column : lastFocusedEditor . editor . getModel ( ) ! . getLineFirstNonWhitespaceColumn ( range . startLineNumber ) ,
101
+ column : editor . editor . getModel ( ) ! . getLineFirstNonWhitespaceColumn ( range . startLineNumber ) ,
95
102
} ) ;
96
- lastFocusedEditor . editor . revealLinesNearTop ( range . startLineNumber , range . endLineNumberExclusive , ScrollType . Smooth ) ;
103
+ editor . editor . revealLinesNearTop ( range . startLineNumber , range . endLineNumberExclusive , ScrollType . Smooth ) ;
97
104
}
98
105
}
99
106
0 commit comments