feat(diff): add persisted side-by-side and wrap toggles to the diff viewer
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using ClaudeDo.Data.Git;
|
||||
using ClaudeDo.Ui;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
using ClaudeDo.Ui.Services;
|
||||
|
||||
@@ -21,6 +24,7 @@ public sealed partial class DiffViewerViewModel : ViewModelBase
|
||||
{
|
||||
private readonly GitService _git;
|
||||
private readonly IWorkerClient _worker;
|
||||
private readonly AppSettings _settings;
|
||||
|
||||
[ObservableProperty]
|
||||
[NotifyPropertyChangedFor(nameof(IsPlanning))]
|
||||
@@ -56,6 +60,31 @@ public sealed partial class DiffViewerViewModel : ViewModelBase
|
||||
[ObservableProperty] private string _displayedDiff = "";
|
||||
[ObservableProperty] private string? _statusMessage;
|
||||
|
||||
// ── View toggles (persisted to ui.config.json) ──────────────────────────
|
||||
[ObservableProperty] private bool _isSplitView;
|
||||
[ObservableProperty] private bool _wrapLines;
|
||||
|
||||
partial void OnIsSplitViewChanged(bool value)
|
||||
{
|
||||
_settings.DiffViewMode = value ? "split" : "unified";
|
||||
PersistViewPreferences();
|
||||
}
|
||||
|
||||
partial void OnWrapLinesChanged(bool value)
|
||||
{
|
||||
_settings.DiffWrapLines = value;
|
||||
PersistViewPreferences();
|
||||
}
|
||||
|
||||
/// A failed preference write must never take the diff viewer down with it; the toggle
|
||||
/// still works for this session, it just won't survive a restart.
|
||||
private void PersistViewPreferences()
|
||||
{
|
||||
try { _settings.Save(); }
|
||||
catch (IOException) { }
|
||||
catch (UnauthorizedAccessException) { }
|
||||
}
|
||||
|
||||
// ── Planning combined toggle ────────────────────────────────────────────
|
||||
[ObservableProperty] private bool _isCombinedMode;
|
||||
[ObservableProperty] private string? _combinedWarning;
|
||||
@@ -63,10 +92,13 @@ public sealed partial class DiffViewerViewModel : ViewModelBase
|
||||
|
||||
public Action? CloseAction { get; set; }
|
||||
|
||||
public DiffViewerViewModel(GitService git, IWorkerClient worker)
|
||||
public DiffViewerViewModel(GitService git, IWorkerClient worker, AppSettings settings)
|
||||
{
|
||||
_git = git;
|
||||
_worker = worker;
|
||||
_settings = settings;
|
||||
_isSplitView = string.Equals(settings.DiffViewMode, "split", StringComparison.OrdinalIgnoreCase);
|
||||
_wrapLines = settings.DiffWrapLines;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
|
||||
@@ -30,6 +30,12 @@
|
||||
|
||||
<DockPanel>
|
||||
|
||||
<!-- View toolbar: layout + wrap, both persisted -->
|
||||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="8" Margin="16,8,16,0">
|
||||
<ToggleButton Content="{loc:Tr modals.diff.splitView}" IsChecked="{Binding IsSplitView}"/>
|
||||
<ToggleButton Content="{loc:Tr modals.diff.wrapLines}" IsChecked="{Binding WrapLines}"/>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Planning toolbar: combined-mode toggle + warning/loading -->
|
||||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Spacing="8" Margin="16,8,16,0"
|
||||
IsVisible="{Binding IsPlanning}">
|
||||
@@ -149,10 +155,10 @@
|
||||
Foreground="{DynamicResource TextMuteBrush}"
|
||||
IsVisible="{Binding SelectedFile.IsEmptyContent}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
|
||||
IsVisible="{Binding SelectedFile.HasLines}">
|
||||
<ctl:DiffLinesView Lines="{Binding SelectedFile.Lines}"/>
|
||||
</ScrollViewer>
|
||||
<ctl:DiffTextView IsVisible="{Binding SelectedFile.HasLines}"
|
||||
File="{Binding SelectedFile}"
|
||||
IsSplit="{Binding IsSplitView}"
|
||||
WrapLines="{Binding WrapLines}"/>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user