feat(ui): add inline conflict model (file/hunk with resolution)
This commit is contained in:
49
src/ClaudeDo.Ui/ViewModels/Conflicts/ConflictModels.cs
Normal file
49
src/ClaudeDo.Ui/ViewModels/Conflicts/ConflictModels.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
namespace ClaudeDo.Ui.ViewModels.Conflicts;
|
||||||
|
|
||||||
|
public sealed partial class ConflictHunk : ObservableObject
|
||||||
|
{
|
||||||
|
public string Ours { get; }
|
||||||
|
public string Theirs { get; }
|
||||||
|
public string? Base { get; }
|
||||||
|
|
||||||
|
[ObservableProperty] private string? _resolution;
|
||||||
|
|
||||||
|
public bool IsResolved => Resolution is not null;
|
||||||
|
|
||||||
|
public ConflictHunk(string ours, string theirs, string? @base)
|
||||||
|
{
|
||||||
|
Ours = ours;
|
||||||
|
Theirs = theirs;
|
||||||
|
Base = @base;
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnResolutionChanged(string? value) => OnPropertyChanged(nameof(IsResolved));
|
||||||
|
|
||||||
|
[RelayCommand] private void AcceptCurrent() => Resolution = Ours;
|
||||||
|
[RelayCommand] private void AcceptIncoming() => Resolution = Theirs;
|
||||||
|
[RelayCommand] private void AcceptBoth() => Resolution = Ours + Theirs;
|
||||||
|
[RelayCommand] private void EditManually() => Resolution ??= Ours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class ConflictFile
|
||||||
|
{
|
||||||
|
public string Path { get; }
|
||||||
|
public IReadOnlyList<ConflictHunk> Hunks { get; }
|
||||||
|
|
||||||
|
public ConflictFile(string path, IReadOnlyList<ConflictHunk> hunks)
|
||||||
|
{
|
||||||
|
Path = path;
|
||||||
|
Hunks = hunks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AllHunksResolved => Hunks.Count > 0 && Hunks.All(h => h.IsResolved);
|
||||||
|
|
||||||
|
/// <summary>Merged file content: concatenation of each hunk's resolution
|
||||||
|
/// (single whole-file hunk today; concatenation stays correct for multi-hunk later).</summary>
|
||||||
|
public string ComposeResolvedContent() => string.Concat(Hunks.Select(h => h.Resolution));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user