Skip to content

Commit fc54eca

Browse files
navn-rfcollonval
andcommitted
Apply suggestions from code review
Co-authored-by: Frédéric Collonval <[email protected]>
1 parent 18ed234 commit fc54eca

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

src/components/FileList.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const CONTEXT_COMMANDS: ContextCommands = {
8080
ContextCommandIDs.gitFileHistory
8181
],
8282
unmodified: [ContextCommandIDs.gitFileHistory],
83-
unmerged: [ContextCommandIDs.gitFileOpen]
83+
unmerged: [ContextCommandIDs.gitFileDiff]
8484
};
8585

8686
const SIMPLE_CONTEXT_COMMANDS: ContextCommands = {
@@ -109,7 +109,7 @@ const SIMPLE_CONTEXT_COMMANDS: ContextCommands = {
109109
ContextCommandIDs.gitFileDelete
110110
],
111111
unmodified: [ContextCommandIDs.gitFileHistory],
112-
unmerged: [ContextCommandIDs.gitFileOpen]
112+
unmerged: [ContextCommandIDs.gitFileDiff]
113113
};
114114

115115
export class FileList extends React.Component<IFileListProps, IFileListState> {
@@ -364,6 +364,7 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
364364
<FileItem
365365
trans={this.props.trans}
366366
actions={!file.is_binary && diffButton}
367+
contextMenu={this.openContextMenu}
367368
file={file}
368369
model={this.props.model}
369370
selected={this._isSelectedFile(file)}

src/components/diff/PlainTextDiff.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PromiseDelegate } from '@lumino/coreutils';
44
import { Widget } from '@lumino/widgets';
55
import { MergeView } from 'codemirror';
66
import { Git } from '../../tokens';
7-
import { mergeView } from './mergeview';
7+
import { mergeView, MergeView as LocalMergeView } from './mergeview';
88

99
/**
1010
* Diff callback to be registered for plain-text files.
@@ -43,7 +43,7 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
4343
Promise.all([
4444
this._model.reference.content(),
4545
this._model.challenger.content(),
46-
this._model.base?.content()
46+
this._model.base?.content() ?? Promise.resolve(null)
4747
])
4848
.then(([reference, challenger, base]) => {
4949
this._reference = reference;
@@ -58,6 +58,13 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
5858
});
5959
}
6060

61+
/**
62+
* Helper to determine if three-way diff should be shown.
63+
*/
64+
private _isConflict(): boolean {
65+
return this._base !== null;
66+
}
67+
6168
/**
6269
* Promise which fulfills when the widget is ready.
6370
*/
@@ -73,7 +80,11 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
7380
this.ready
7481
.then(() => {
7582
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+
);
7788
}
7889
})
7990
.catch(reason => {
@@ -107,17 +118,19 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
107118
if (this._challenger !== null) {
108119
this._challenger = await this._model.challenger.content();
109120
}
121+
if (this._base !== null) {
122+
this._base = (await this._model.base?.content()) ?? null;
123+
}
110124

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+
);
113130

114-
this.createDiffView(this._challenger, this._reference, this._base);
115131
this._challenger = null;
116132
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;
121134
} catch (reason) {
122135
this.showError(reason);
123136
}
@@ -142,36 +155,37 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
142155

143156
/**
144157
* Create the Plain Text Diff view
158+
*
159+
* Note: baseContent will only be passed when displaying
160+
* a three-way merge conflict.
145161
*/
146162
protected async createDiffView(
147163
challengerContent: string,
148164
referenceContent: string,
149165
baseContent?: string
150166
): Promise<void> {
151167
if (!this._mergeView) {
152-
// Empty base content ("") can be an edge case.
153-
const isMergeConflict = baseContent !== undefined;
154-
155168
const mode =
156169
Mode.findByFileName(this._model.filename) ||
157170
Mode.findBest(this._model.filename);
158171

159-
let options: Parameters<typeof mergeView>[1] = {
172+
let options: LocalMergeView.IMergeViewEditorConfiguration = {
160173
value: challengerContent,
161174
orig: referenceContent,
162175
mode: mode.mime,
163176
...this.getDefaultOptions()
164177
};
165178

166179
// Show three-way diff on merge conflict
167-
if (isMergeConflict) {
180+
// Note: Empty base content ("") can be an edge case.
181+
if (baseContent !== undefined) {
168182
options = {
169183
...options,
170184
value: baseContent,
171185
origRight: referenceContent,
172186
origLeft: challengerContent,
173-
readOnly: true,
174-
revertButtons: false
187+
readOnly: false,
188+
revertButtons: true
175189
};
176190
}
177191

@@ -221,5 +235,5 @@ export class PlainTextDiff extends Widget implements Git.Diff.IDiffWidget {
221235

222236
private _reference: string | null = null;
223237
private _challenger: string | null = null;
224-
private _base?: string | null;
238+
private _base: string | null = null;
225239
}

src/tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ export namespace Git {
535535
currentRef: string | SpecialRef;
536536
previousRef: string | SpecialRef;
537537
// Used only during merge conflict diffs
538-
baseRef?: string | SpecialRef;
538+
baseRef?: string;
539539
}
540540

541541
/**

0 commit comments

Comments
 (0)