Skip to content

Commit 3936008

Browse files
authored
feature: add added/removed line counts to diff view (#2194)
1 parent 14db2d5 commit 3936008

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/Commands/Diff.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ private void ParseLine(string line)
194194
return;
195195
}
196196

197+
_result.TextDiff.DeletedLines++;
197198
_last = new Models.TextDiffLine(Models.TextDiffLineType.Deleted, line.Substring(1), _oldLine, 0);
198199
_deleted.Add(_last);
199200
_oldLine++;
@@ -207,6 +208,7 @@ private void ParseLine(string line)
207208
return;
208209
}
209210

211+
_result.TextDiff.AddedLines++;
210212
_last = new Models.TextDiffLine(Models.TextDiffLineType.Added, line.Substring(1), 0, _newLine);
211213
_added.Add(_last);
212214
_newLine++;

src/Models/DiffResult.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public partial class TextDiff
5555
{
5656
public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>();
5757
public int MaxLineNumber = 0;
58+
public int AddedLines { get; set; } = 0;
59+
public int DeletedLines { get; set; } = 0;
5860

5961
public TextDiffSelection MakeSelection(int startLine, int endLine, bool isCombined, bool isOldSide)
6062
{

src/ViewModels/TextDiffContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class TextDiffContext : ObservableObject
2828
{
2929
public Models.DiffOption Option => _option;
3030
public Models.TextDiff Data => _data;
31+
public int AddedLines => _data?.AddedLines ?? 0;
32+
public int DeletedLines => _data?.DeletedLines ?? 0;
3133

3234
public Vector ScrollOffset
3335
{

src/Views/DiffView.axaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,29 @@
6767
<ContentControl Content="{Binding Content, Mode=OneWay}" IsVisible="{Binding IsTextDiff}">
6868
<ContentControl.DataTemplates>
6969
<DataTemplate DataType="vm:TextDiffContext">
70-
<TextBlock Margin="0,0,0,0" FontSize="11" Text="{Binding BlockNavigation.Indicator}"/>
70+
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
71+
<TextBlock Margin="0,0,0,0" FontSize="11" Text="{Binding BlockNavigation.Indicator}"/>
72+
<Border Height="16"
73+
Background="{DynamicResource Brush.Diff.AddedBG}"
74+
CornerRadius="8"
75+
VerticalAlignment="Center"
76+
IsVisible="{Binding AddedLines, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
77+
<TextBlock FontSize="10"
78+
Margin="8,0"
79+
Foreground="{DynamicResource Brush.FG1}"
80+
Text="{Binding AddedLines, StringFormat=+{0}}"/>
81+
</Border>
82+
<Border Height="16"
83+
Background="{DynamicResource Brush.Diff.DeletedBG}"
84+
CornerRadius="8"
85+
VerticalAlignment="Center"
86+
IsVisible="{Binding DeletedLines, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
87+
<TextBlock FontSize="10"
88+
Margin="8,0"
89+
Foreground="{DynamicResource Brush.FG1}"
90+
Text="{Binding DeletedLines, StringFormat=-{0}}"/>
91+
</Border>
92+
</StackPanel>
7193
</DataTemplate>
7294
</ContentControl.DataTemplates>
7395
</ContentControl>

0 commit comments

Comments
 (0)