Skip to content

Commit 1d80d00

Browse files
committed
feature: show MINE and THEIRS revision in merge conflict editor
- Rename some resources about conflicts - Rename `MergeConflictEditor.XXXDiffLines` to `MergeConflictEditor.XXXLines` - It's not necessary to show commit info in tooltip for conflict revisions - New UI/UX for merge conflict editor Signed-off-by: leo <longshuang@msn.cn>
1 parent 1038855 commit 1d80d00

File tree

8 files changed

+172
-125
lines changed

8 files changed

+172
-125
lines changed

src/Resources/Themes.axaml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<Color x:Key="Color.Badge">#FFB0CEE8</Color>
1212
<Color x:Key="Color.BadgeFG">#FF1F1F1F</Color>
1313
<Color x:Key="Color.Conflict">#FF836C2E</Color>
14-
<Color x:Key="Color.ConflictForeground">#FFFFFFFF</Color>
14+
<Color x:Key="Color.Conflict.Foreground">#FFFFFFFF</Color>
15+
<Color x:Key="Color.Conflict.MineBG">#400078D7</Color>
16+
<Color x:Key="Color.Conflict.TheirsBG">#40FF8C00</Color>
1517
<Color x:Key="Color.Border0">#FFCFCFCF</Color>
1618
<Color x:Key="Color.Border1">#FF898989</Color>
1719
<Color x:Key="Color.Border2">#FFCFCFCF</Color>
@@ -24,11 +26,6 @@
2426
<Color x:Key="Color.Diff.DeletedBG">#80FF9797</Color>
2527
<Color x:Key="Color.Diff.AddedHighlight">#A7E1A7</Color>
2628
<Color x:Key="Color.Diff.DeletedHighlight">#F19B9D</Color>
27-
<Color x:Key="Color.Diff.MineBG">#400078D7</Color>
28-
<Color x:Key="Color.Diff.TheirsBG">#40FF8C00</Color>
29-
<Color x:Key="Color.Diff.MineHeader">#FF0078D7</Color>
30-
<Color x:Key="Color.Diff.TheirsHeader">#FFFF8C00</Color>
31-
<Color x:Key="Color.Diff.CurrentConflict">#40FFFF00</Color>
3229
<Color x:Key="Color.Link">#0000EE</Color>
3330
<Color x:Key="Color.InlineCode">#FFE4E4E4</Color>
3431
<Color x:Key="Color.InlineCodeFG">Black</Color>
@@ -44,7 +41,9 @@
4441
<Color x:Key="Color.Badge">#FF8F8F8F</Color>
4542
<Color x:Key="Color.BadgeFG">#FFDDDDDD</Color>
4643
<Color x:Key="Color.Conflict">#FFFAFAD2</Color>
47-
<Color x:Key="Color.ConflictForeground">#FF252525</Color>
44+
<Color x:Key="Color.Conflict.Foreground">#FF252525</Color>
45+
<Color x:Key="Color.Conflict.MineBG">#400078D7</Color>
46+
<Color x:Key="Color.Conflict.TheirsBG">#40FF8C00</Color>
4847
<Color x:Key="Color.Border0">#FF181818</Color>
4948
<Color x:Key="Color.Border1">#FF7C7C7C</Color>
5049
<Color x:Key="Color.Border2">#FF404040</Color>
@@ -57,11 +56,6 @@
5756
<Color x:Key="Color.Diff.DeletedBG">#C0633F3E</Color>
5857
<Color x:Key="Color.Diff.AddedHighlight">#A0308D3C</Color>
5958
<Color x:Key="Color.Diff.DeletedHighlight">#A09F4247</Color>
60-
<Color x:Key="Color.Diff.MineBG">#400078D7</Color>
61-
<Color x:Key="Color.Diff.TheirsBG">#40FF8C00</Color>
62-
<Color x:Key="Color.Diff.MineHeader">#FF0078D7</Color>
63-
<Color x:Key="Color.Diff.TheirsHeader">#FFFF8C00</Color>
64-
<Color x:Key="Color.Diff.CurrentConflict">#40FFFF00</Color>
6559
<Color x:Key="Color.Link">#4DAAFC</Color>
6660
<Color x:Key="Color.InlineCode">#FF383838</Color>
6761
<Color x:Key="Color.InlineCodeFG">#FFF0F0F0</Color>
@@ -77,7 +71,9 @@
7771
<SolidColorBrush x:Key="Brush.Badge" Color="{DynamicResource Color.Badge}"/>
7872
<SolidColorBrush x:Key="Brush.BadgeFG" Color="{DynamicResource Color.BadgeFG}"/>
7973
<SolidColorBrush x:Key="Brush.Conflict" Color="{DynamicResource Color.Conflict}"/>
80-
<SolidColorBrush x:Key="Brush.ConflictForeground" Color="{DynamicResource Color.ConflictForeground}"/>
74+
<SolidColorBrush x:Key="Brush.Conflict.Foreground" Color="{DynamicResource Color.Conflict.Foreground}"/>
75+
<SolidColorBrush x:Key="Brush.Conflict.MineBG" Color="{DynamicResource Color.Conflict.MineBG}"/>
76+
<SolidColorBrush x:Key="Brush.Conflict.TheirsBG" Color="{DynamicResource Color.Conflict.TheirsBG}"/>
8177
<SolidColorBrush x:Key="Brush.Border0" Color="{DynamicResource Color.Border0}"/>
8278
<SolidColorBrush x:Key="Brush.Border1" Color="{DynamicResource Color.Border1}"/>
8379
<SolidColorBrush x:Key="Brush.Border2" Color="{DynamicResource Color.Border2}"/>
@@ -92,11 +88,6 @@
9288
<SolidColorBrush x:Key="Brush.Diff.DeletedBG" Color="{DynamicResource Color.Diff.DeletedBG}"/>
9389
<SolidColorBrush x:Key="Brush.Diff.AddedHighlight" Color="{DynamicResource Color.Diff.AddedHighlight}"/>
9490
<SolidColorBrush x:Key="Brush.Diff.DeletedHighlight" Color="{DynamicResource Color.Diff.DeletedHighlight}"/>
95-
<SolidColorBrush x:Key="Brush.Diff.MineBG" Color="{DynamicResource Color.Diff.MineBG}"/>
96-
<SolidColorBrush x:Key="Brush.Diff.TheirsBG" Color="{DynamicResource Color.Diff.TheirsBG}"/>
97-
<SolidColorBrush x:Key="Brush.Diff.MineHeader" Color="{DynamicResource Color.Diff.MineHeader}"/>
98-
<SolidColorBrush x:Key="Brush.Diff.TheirsHeader" Color="{DynamicResource Color.Diff.TheirsHeader}"/>
99-
<SolidColorBrush x:Key="Brush.Diff.CurrentConflict" Color="{DynamicResource Color.Diff.CurrentConflict}"/>
10091
<SolidColorBrush x:Key="Brush.Link" Color="{DynamicResource Color.Link}"/>
10192
<SolidColorBrush x:Key="Brush.InlineCode" Color="{DynamicResource Color.InlineCode}"/>
10293
<SolidColorBrush x:Key="Brush.InlineCodeFG" Color="{DynamicResource Color.InlineCodeFG}"/>

src/ViewModels/Conflict.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public Conflict(Repository repo, WorkingCopy wc, Models.Change change)
5252
if (CanMerge)
5353
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).GetResult();
5454

55-
var head = new Commands.QuerySingleCommit(repo.FullPath, "HEAD").GetResult();
55+
_head = new Commands.QuerySingleCommit(repo.FullPath, "HEAD").GetResult();
5656
(Mine, Theirs) = wc.InProgressContext switch
5757
{
58-
CherryPickInProgress cherryPick => (head, cherryPick.Head),
58+
CherryPickInProgress cherryPick => (_head, cherryPick.Head),
5959
RebaseInProgress rebase => (rebase.Onto, rebase.StoppedAt),
60-
RevertInProgress revert => (head, revert.Head),
61-
MergeInProgress merge => (head, merge.Source),
62-
_ => (head, (object)"Stash or Patch"),
60+
RevertInProgress revert => (_head, revert.Head),
61+
MergeInProgress merge => (_head, merge.Source),
62+
_ => (_head, (object)"Stash or Patch"),
6363
};
6464
}
6565

@@ -76,7 +76,7 @@ public async Task UseMineAsync()
7676
public async Task MergeAsync()
7777
{
7878
if (CanMerge)
79-
await App.ShowDialog(new MergeConflictEditor(_repo, _change.Path));
79+
await App.ShowDialog(new MergeConflictEditor(_repo, _head, _change.Path));
8080
}
8181

8282
public async Task MergeExternalAsync()
@@ -87,6 +87,7 @@ public async Task MergeExternalAsync()
8787

8888
private Repository _repo = null;
8989
private WorkingCopy _wc = null;
90+
private Models.Commit _head = null;
9091
private Models.Change _change = null;
9192
}
9293
}

src/ViewModels/MergeConflictEditor.cs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,44 @@ public string FilePath
1616
get => _filePath;
1717
}
1818

19+
public object Mine
20+
{
21+
get;
22+
}
23+
24+
public object Theirs
25+
{
26+
get;
27+
}
28+
1929
public string Error
2030
{
2131
get => _error;
2232
private set => SetProperty(ref _error, value);
2333
}
2434

25-
public List<Models.ConflictLine> OursDiffLines
35+
public List<Models.ConflictLine> OursLines
2636
{
27-
get => _oursDiffLines;
28-
private set => SetProperty(ref _oursDiffLines, value);
37+
get => _oursLines;
38+
private set => SetProperty(ref _oursLines, value);
2939
}
3040

31-
public List<Models.ConflictLine> TheirsDiffLines
41+
public List<Models.ConflictLine> TheirsLines
3242
{
33-
get => _theirsDiffLines;
34-
private set => SetProperty(ref _theirsDiffLines, value);
43+
get => _theirsLines;
44+
private set => SetProperty(ref _theirsLines, value);
3545
}
3646

37-
public List<Models.ConflictLine> ResultDiffLines
47+
public List<Models.ConflictLine> ResultLines
3848
{
39-
get => _resultDiffLines;
40-
private set => SetProperty(ref _resultDiffLines, value);
49+
get => _resultLines;
50+
private set => SetProperty(ref _resultLines, value);
4151
}
4252

43-
public int DiffMaxLineNumber
53+
public int MaxLineNumber
4454
{
45-
get => _diffMaxLineNumber;
46-
private set => SetProperty(ref _diffMaxLineNumber, value);
55+
get => _maxLineNumber;
56+
private set => SetProperty(ref _maxLineNumber, value);
4757
}
4858

4959
public int UnsolvedCount
@@ -69,11 +79,20 @@ public IReadOnlyList<Models.ConflictRegion> ConflictRegions
6979
get => _conflictRegions;
7080
}
7181

72-
public MergeConflictEditor(Repository repo, string filePath)
82+
public MergeConflictEditor(Repository repo, Models.Commit head, string filePath)
7383
{
7484
_repo = repo;
7585
_filePath = filePath;
7686

87+
(Mine, Theirs) = repo.InProgressContext switch
88+
{
89+
CherryPickInProgress cherryPick => (head, cherryPick.Head),
90+
RebaseInProgress rebase => (rebase.Onto, rebase.StoppedAt),
91+
RevertInProgress revert => (head, revert.Head),
92+
MergeInProgress merge => (head, merge.Source),
93+
_ => (head, (object)"Stash or Patch"),
94+
};
95+
7796
var workingCopyPath = Path.Combine(_repo.FullPath, _filePath);
7897
var workingCopyContent = string.Empty;
7998
if (File.Exists(workingCopyPath))
@@ -291,28 +310,27 @@ private void ParseOriginalContent(string content)
291310
}
292311
}
293312

294-
var maxLineNumber = Math.Max(oursLineNumber, theirsLineNumber);
295-
DiffMaxLineNumber = maxLineNumber;
296-
OursDiffLines = oursLines;
297-
TheirsDiffLines = theirsLines;
313+
MaxLineNumber = Math.Max(oursLineNumber, theirsLineNumber);
314+
OursLines = oursLines;
315+
TheirsLines = theirsLines;
298316
}
299317

300318
private void RefreshDisplayData()
301319
{
302320
var resultLines = new List<Models.ConflictLine>();
303321
_lineStates.Clear();
304322

305-
if (_oursDiffLines == null || _oursDiffLines.Count == 0)
323+
if (_oursLines == null || _oursLines.Count == 0)
306324
{
307-
ResultDiffLines = resultLines;
325+
ResultLines = resultLines;
308326
return;
309327
}
310328

311329
int resultLineNumber = 1;
312330
int currentLine = 0;
313331
int conflictIdx = 0;
314332

315-
while (currentLine < _oursDiffLines.Count)
333+
while (currentLine < _oursLines.Count)
316334
{
317335
// Check if we're at a conflict region
318336
Models.ConflictRegion currentRegion = null;
@@ -424,7 +442,7 @@ private void RefreshDisplayData()
424442
}
425443
else
426444
{
427-
var oursLine = _oursDiffLines[currentLine];
445+
var oursLine = _oursLines[currentLine];
428446
resultLines.Add(new(oursLine.Type, oursLine.Content, resultLineNumber));
429447
_lineStates.Add(Models.ConflictLineState.Normal);
430448
resultLineNumber++;
@@ -433,7 +451,7 @@ private void RefreshDisplayData()
433451
}
434452

435453
SelectedChunk = null;
436-
ResultDiffLines = resultLines;
454+
ResultLines = resultLines;
437455

438456
var unsolved = new List<int>();
439457
for (var i = 0; i < _conflictRegions.Count; i++)
@@ -450,10 +468,10 @@ private void RefreshDisplayData()
450468
private readonly string _filePath;
451469
private string _originalContent = string.Empty;
452470
private int _unsolvedCount = 0;
453-
private int _diffMaxLineNumber = 0;
454-
private List<Models.ConflictLine> _oursDiffLines = [];
455-
private List<Models.ConflictLine> _theirsDiffLines = [];
456-
private List<Models.ConflictLine> _resultDiffLines = [];
471+
private int _maxLineNumber = 0;
472+
private List<Models.ConflictLine> _oursLines = [];
473+
private List<Models.ConflictLine> _theirsLines = [];
474+
private List<Models.ConflictLine> _resultLines = [];
457475
private List<Models.ConflictRegion> _conflictRegions = [];
458476
private List<Models.ConflictLineState> _lineStates = [];
459477
private Vector _scrollOffset = Vector.Zero;

src/Views/Conflict.axaml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,7 @@
3636
Foreground="DarkOrange"
3737
TextDecorations="Underline"
3838
Cursor="Hand"
39-
PointerPressed="OnPressedSHA"
40-
ToolTip.Tip="{Binding}"
41-
ToolTip.ShowDelay="0">
42-
<TextBlock.DataTemplates>
43-
<DataTemplate DataType="m:Commit">
44-
<StackPanel MinWidth="400" Orientation="Vertical">
45-
<Grid ColumnDefinitions="Auto,*,Auto">
46-
<v:Avatar Grid.Column="0" Width="16" Height="16" VerticalAlignment="Center" IsHitTestVisible="False" User="{Binding Author}"/>
47-
<TextBlock Grid.Column="1" Text="{Binding Author.Name}" Margin="8,0,0,0"/>
48-
<TextBlock Grid.Column="2" Text="{Binding CommitterTimeStr}" Foreground="{DynamicResource Brush.FG2}" Margin="8,0,0,0"/>
49-
</Grid>
50-
51-
<TextBlock Margin="0,8,0,0" Text="{Binding Subject}" TextWrapping="Wrap"/>
52-
</StackPanel>
53-
</DataTemplate>
54-
</TextBlock.DataTemplates>
55-
</TextBlock>
39+
PointerPressed="OnPressedSHA"/>
5640
<TextBlock Margin="4,0,0,0" Text="{Binding Subject}"/>
5741
</StackPanel>
5842
</DataTemplate>

0 commit comments

Comments
 (0)