@@ -4,7 +4,7 @@ import { PromiseDelegate } from '@lumino/coreutils';
4
4
import { Widget } from '@lumino/widgets' ;
5
5
import { MergeView } from 'codemirror' ;
6
6
import { Git } from '../../tokens' ;
7
- import { mergeView } from './mergeview' ;
7
+ import { mergeView , MergeView as LocalMergeView } from './mergeview' ;
8
8
9
9
/**
10
10
* Diff callback to be registered for plain-text files.
@@ -43,7 +43,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
43
43
Promise . all ( [
44
44
this . _model . reference . content ( ) ,
45
45
this . _model . challenger . content ( ) ,
46
- this . _model . base ?. content ( )
46
+ this . _model . base ?. content ( ) ?? Promise . resolve ( null )
47
47
] )
48
48
. then ( ( [ reference , challenger , base ] ) => {
49
49
this . _reference = reference ;
@@ -58,6 +58,13 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
58
58
} ) ;
59
59
}
60
60
61
+ /**
62
+ * Helper to determine if three-way diff should be shown.
63
+ */
64
+ private _isConflict ( ) : boolean {
65
+ return this . _base !== null ;
66
+ }
67
+
61
68
/**
62
69
* Promise which fulfills when the widget is ready.
63
70
*/
@@ -73,7 +80,11 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
73
80
this . ready
74
81
. then ( ( ) => {
75
82
if ( this . _challenger !== null && this . _reference !== null ) {
76
- this . createDiffView ( this . _challenger , this . _reference , this . _base ) ;
83
+ this . createDiffView (
84
+ this . _challenger ,
85
+ this . _reference ,
86
+ this . _isConflict ( ) ? this . _base : undefined
87
+ ) ;
77
88
}
78
89
} )
79
90
. catch ( reason => {
@@ -107,17 +118,19 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
107
118
if ( this . _challenger !== null ) {
108
119
this . _challenger = await this . _model . challenger . content ( ) ;
109
120
}
121
+ if ( this . _base !== null ) {
122
+ this . _base = ( await this . _model . base ?. content ( ) ) ?? null ;
123
+ }
110
124
111
- // Request base content only if base was provided in the model
112
- this . _base = await this . _model . base ?. content ( ) ;
125
+ this . createDiffView (
126
+ this . _challenger ,
127
+ this . _reference ,
128
+ this . _isConflict ( ) ? this . _base : undefined
129
+ ) ;
113
130
114
- this . createDiffView ( this . _challenger , this . _reference , this . _base ) ;
115
131
this . _challenger = null ;
116
132
this . _reference = null ;
117
-
118
- // Set to null only if base was provided in the model
119
- // else leave as undefined
120
- this . _base = ! ! this . _model . base && null ;
133
+ this . _base = null ;
121
134
} catch ( reason ) {
122
135
this . showError ( reason ) ;
123
136
}
@@ -142,36 +155,37 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
142
155
143
156
/**
144
157
* Create the Plain Text Diff view
158
+ *
159
+ * Note: baseContent will only be passed when displaying
160
+ * a three-way merge conflict.
145
161
*/
146
162
protected async createDiffView (
147
163
challengerContent : string ,
148
164
referenceContent : string ,
149
165
baseContent ?: string
150
166
) : Promise < void > {
151
167
if ( ! this . _mergeView ) {
152
- // Empty base content ("") can be an edge case.
153
- const isMergeConflict = baseContent !== undefined ;
154
-
155
168
const mode =
156
169
Mode . findByFileName ( this . _model . filename ) ||
157
170
Mode . findBest ( this . _model . filename ) ;
158
171
159
- let options : Parameters < typeof mergeView > [ 1 ] = {
172
+ let options : LocalMergeView . IMergeViewEditorConfiguration = {
160
173
value : challengerContent ,
161
174
orig : referenceContent ,
162
175
mode : mode . mime ,
163
176
...this . getDefaultOptions ( )
164
177
} ;
165
178
166
179
// Show three-way diff on merge conflict
167
- if ( isMergeConflict ) {
180
+ // Note: Empty base content ("") can be an edge case.
181
+ if ( baseContent !== undefined ) {
168
182
options = {
169
183
...options ,
170
184
value : baseContent ,
171
185
origRight : referenceContent ,
172
186
origLeft : challengerContent ,
173
- readOnly : true ,
174
- revertButtons : false
187
+ readOnly : false ,
188
+ revertButtons : true
175
189
} ;
176
190
}
177
191
@@ -221,5 +235,5 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
221
235
222
236
private _reference : string | null = null ;
223
237
private _challenger : string | null = null ;
224
- private _base ? : string | null ;
238
+ private _base : string | null = null ;
225
239
}
0 commit comments