feat(ui): show status messages and real diff-stats in DiffModal
- Count additions/deletions per file as lines are parsed. - Surface load failures and empty-diff states via StatusMessage. - Pass the worktree base commit so diffs render against the branch base, not just the working-tree HEAD.
This commit is contained in:
@@ -31,8 +31,8 @@ public sealed class DiffLineViewModel
|
||||
public sealed class DiffFileViewModel
|
||||
{
|
||||
public required string Path { get; init; }
|
||||
public int Additions { get; init; }
|
||||
public int Deletions { get; init; }
|
||||
public int Additions { get; set; }
|
||||
public int Deletions { get; set; }
|
||||
public ObservableCollection<DiffLineViewModel> Lines { get; } = new();
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ public sealed partial class DiffModalViewModel : ViewModelBase
|
||||
public ObservableCollection<DiffFileViewModel> Files { get; } = new();
|
||||
|
||||
[ObservableProperty] private DiffFileViewModel? _selectedFile;
|
||||
[ObservableProperty] private string? _statusMessage;
|
||||
|
||||
// Injected action to close the owning Window
|
||||
public Action? CloseAction { get; set; }
|
||||
@@ -79,6 +80,7 @@ public sealed partial class DiffModalViewModel : ViewModelBase
|
||||
public async Task LoadAsync(CancellationToken ct = default)
|
||||
{
|
||||
Files.Clear();
|
||||
StatusMessage = null;
|
||||
|
||||
string raw;
|
||||
try
|
||||
@@ -87,9 +89,17 @@ public sealed partial class DiffModalViewModel : ViewModelBase
|
||||
? await _git.GetBranchDiffAsync(WorktreePath, BaseRef, ct)
|
||||
: await _git.GetDiffAsync(WorktreePath, ct);
|
||||
}
|
||||
catch { return; }
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusMessage = $"Failed to load diff: {ex.Message}";
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(raw)) return;
|
||||
if (string.IsNullOrWhiteSpace(raw))
|
||||
{
|
||||
StatusMessage = "No changes to show.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse unified diff — state machine over lines
|
||||
DiffFileViewModel? current = null;
|
||||
@@ -134,7 +144,7 @@ public sealed partial class DiffModalViewModel : ViewModelBase
|
||||
NewNo = newLine++,
|
||||
Text = line.Length > 1 ? line[1..] : "",
|
||||
});
|
||||
// Count additions on the file VM
|
||||
current.Additions++;
|
||||
}
|
||||
else if (line.StartsWith('-'))
|
||||
{
|
||||
@@ -144,6 +154,7 @@ public sealed partial class DiffModalViewModel : ViewModelBase
|
||||
OldNo = oldLine++,
|
||||
Text = line.Length > 1 ? line[1..] : "",
|
||||
});
|
||||
current.Deletions++;
|
||||
}
|
||||
else if (line.StartsWith(' '))
|
||||
{
|
||||
@@ -158,6 +169,7 @@ public sealed partial class DiffModalViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
SelectedFile = Files.Count > 0 ? Files[0] : null;
|
||||
if (Files.Count == 0) StatusMessage = "No changes to show.";
|
||||
}
|
||||
|
||||
private static void ParseHunkHeader(string header, out int oldStart, out int newStart)
|
||||
|
||||
Reference in New Issue
Block a user