refactor(ui): render worktree modal diff via canonical DiffLinesView
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Avalonia.Data.Converters;
|
|
||||||
using Avalonia.Media;
|
|
||||||
using ClaudeDo.Ui.ViewModels.Modals;
|
|
||||||
|
|
||||||
namespace ClaudeDo.Ui.Converters;
|
|
||||||
|
|
||||||
public sealed class DiffLineKindToBrushConverter : IValueConverter
|
|
||||||
{
|
|
||||||
private static readonly ISolidColorBrush Added = new SolidColorBrush(Color.Parse("#66BB6A"));
|
|
||||||
private static readonly ISolidColorBrush Removed = new SolidColorBrush(Color.Parse("#EF5350"));
|
|
||||||
private static readonly ISolidColorBrush Hunk = new SolidColorBrush(Color.Parse("#42A5F5"));
|
|
||||||
private static readonly ISolidColorBrush Header = new SolidColorBrush(Color.Parse("#9E9E9E"));
|
|
||||||
private static readonly ISolidColorBrush Default = new SolidColorBrush(Color.Parse("#CFD8DC"));
|
|
||||||
|
|
||||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
|
|
||||||
value is WorktreeDiffLineKind kind
|
|
||||||
? kind switch
|
|
||||||
{
|
|
||||||
WorktreeDiffLineKind.Added => Added,
|
|
||||||
WorktreeDiffLineKind.Removed => Removed,
|
|
||||||
WorktreeDiffLineKind.Hunk => Hunk,
|
|
||||||
WorktreeDiffLineKind.Header => Header,
|
|
||||||
_ => Default,
|
|
||||||
}
|
|
||||||
: Default;
|
|
||||||
|
|
||||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
||||||
=> throw new NotSupportedException();
|
|
||||||
}
|
|
||||||
@@ -5,14 +5,6 @@ using ClaudeDo.Data.Git;
|
|||||||
|
|
||||||
namespace ClaudeDo.Ui.ViewModels.Modals;
|
namespace ClaudeDo.Ui.ViewModels.Modals;
|
||||||
|
|
||||||
public enum WorktreeDiffLineKind { Header, Hunk, Added, Removed, Context }
|
|
||||||
|
|
||||||
public sealed partial class WorktreeDiffLineViewModel : ViewModelBase
|
|
||||||
{
|
|
||||||
public required string Text { get; init; }
|
|
||||||
public required WorktreeDiffLineKind Kind { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed partial class WorktreeNodeViewModel : ViewModelBase
|
public sealed partial class WorktreeNodeViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
public required string Name { get; init; }
|
public required string Name { get; init; }
|
||||||
@@ -28,7 +20,7 @@ public sealed partial class WorktreeModalViewModel : ViewModelBase
|
|||||||
private readonly GitService _git;
|
private readonly GitService _git;
|
||||||
|
|
||||||
public ObservableCollection<WorktreeNodeViewModel> Root { get; } = new();
|
public ObservableCollection<WorktreeNodeViewModel> Root { get; } = new();
|
||||||
public ObservableCollection<WorktreeDiffLineViewModel> SelectedFileDiffLines { get; } = new();
|
public ObservableCollection<DiffLineViewModel> SelectedFileDiffLines { get; } = new();
|
||||||
|
|
||||||
[ObservableProperty] private string _worktreePath = "";
|
[ObservableProperty] private string _worktreePath = "";
|
||||||
[ObservableProperty] private string? _baseCommit;
|
[ObservableProperty] private string? _baseCommit;
|
||||||
@@ -64,19 +56,8 @@ public sealed partial class WorktreeModalViewModel : ViewModelBase
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var line in diff.Split('\n'))
|
foreach (var line in UnifiedDiffParser.Flatten(UnifiedDiffParser.Parse(diff)))
|
||||||
{
|
SelectedFileDiffLines.Add(line);
|
||||||
var kind = line switch
|
|
||||||
{
|
|
||||||
_ when line.StartsWith("+++") || line.StartsWith("---") => WorktreeDiffLineKind.Header,
|
|
||||||
_ when line.StartsWith("@@") => WorktreeDiffLineKind.Hunk,
|
|
||||||
_ when line.StartsWith('+') => WorktreeDiffLineKind.Added,
|
|
||||||
_ when line.StartsWith('-') => WorktreeDiffLineKind.Removed,
|
|
||||||
_ when line.StartsWith("diff ") || line.StartsWith("index ") || line.StartsWith("\\ ") => WorktreeDiffLineKind.Header,
|
|
||||||
_ => WorktreeDiffLineKind.Context,
|
|
||||||
};
|
|
||||||
SelectedFileDiffLines.Add(new WorktreeDiffLineViewModel { Text = line, Kind = kind });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[RelayCommand]
|
[RelayCommand]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:vm="using:ClaudeDo.Ui.ViewModels.Modals"
|
xmlns:vm="using:ClaudeDo.Ui.ViewModels.Modals"
|
||||||
xmlns:converters="using:ClaudeDo.Ui.Converters"
|
xmlns:converters="using:ClaudeDo.Ui.Converters"
|
||||||
|
xmlns:ctl="using:ClaudeDo.Ui.Views.Controls"
|
||||||
xmlns:loc="using:ClaudeDo.Ui.Localization"
|
xmlns:loc="using:ClaudeDo.Ui.Localization"
|
||||||
x:Class="ClaudeDo.Ui.Views.Modals.WorktreeModalView"
|
x:Class="ClaudeDo.Ui.Views.Modals.WorktreeModalView"
|
||||||
x:DataType="vm:WorktreeModalViewModel"
|
x:DataType="vm:WorktreeModalViewModel"
|
||||||
@@ -16,10 +17,6 @@
|
|||||||
CanResize="True"
|
CanResize="True"
|
||||||
TransparencyLevelHint="AcrylicBlur">
|
TransparencyLevelHint="AcrylicBlur">
|
||||||
|
|
||||||
<Window.Resources>
|
|
||||||
<converters:DiffLineKindToBrushConverter x:Key="DiffLineKindToBrush"/>
|
|
||||||
</Window.Resources>
|
|
||||||
|
|
||||||
<Window.KeyBindings>
|
<Window.KeyBindings>
|
||||||
<KeyBinding Gesture="Escape" Command="{Binding CloseCommand}"/>
|
<KeyBinding Gesture="Escape" Command="{Binding CloseCommand}"/>
|
||||||
</Window.KeyBindings>
|
</Window.KeyBindings>
|
||||||
@@ -89,17 +86,7 @@
|
|||||||
HorizontalScrollBarVisibility="Auto"
|
HorizontalScrollBarVisibility="Auto"
|
||||||
VerticalScrollBarVisibility="Auto"
|
VerticalScrollBarVisibility="Auto"
|
||||||
Margin="4,0,8,8">
|
Margin="4,0,8,8">
|
||||||
<ItemsControl ItemsSource="{Binding SelectedFileDiffLines}">
|
<ctl:DiffLinesView Lines="{Binding SelectedFileDiffLines}"/>
|
||||||
<ItemsControl.ItemTemplate>
|
|
||||||
<DataTemplate DataType="vm:WorktreeDiffLineViewModel">
|
|
||||||
<SelectableTextBlock Text="{Binding Text}"
|
|
||||||
FontFamily="{DynamicResource MonoFont}"
|
|
||||||
FontSize="{StaticResource FontSizeMono}"
|
|
||||||
Foreground="{Binding Kind, Converter={StaticResource DiffLineKindToBrush}}"
|
|
||||||
TextWrapping="NoWrap"/>
|
|
||||||
</DataTemplate>
|
|
||||||
</ItemsControl.ItemTemplate>
|
|
||||||
</ItemsControl>
|
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Reference in New Issue
Block a user