refactor: rewrite TextDiffView

This commit is contained in:
leo 2024-06-12 21:12:45 +08:00
parent eab680ae55
commit 68061f82b1
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
6 changed files with 318 additions and 497 deletions

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Avalonia;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
@ -11,7 +11,13 @@ namespace SourceGit.ViewModels
public List<Models.TextDiffLine> New { get; set; } = new List<Models.TextDiffLine>();
public int MaxLineNumber = 0;
public TwoSideTextDiff(Models.TextDiff diff)
public Vector SyncScrollOffset
{
get => _syncScrollOffset;
set => SetProperty(ref _syncScrollOffset, value);
}
public TwoSideTextDiff(Models.TextDiff diff, TwoSideTextDiff previous = null)
{
File = diff.File;
MaxLineNumber = diff.MaxLineNumber;
@ -35,6 +41,9 @@ namespace SourceGit.ViewModels
}
FillEmptyLines();
if (previous != null && previous.File == File)
_syncScrollOffset = previous._syncScrollOffset;
}
private void FillEmptyLines()
@ -52,5 +61,7 @@ namespace SourceGit.ViewModels
New.Add(new Models.TextDiffLine());
}
}
private Vector _syncScrollOffset = Vector.Zero;
}
}

View file

@ -379,24 +379,16 @@ namespace SourceGit.ViewModels
if (isUnstaged)
{
if (changes.Count == _unstaged.Count && _staged.Count == 0)
{
PopupHost.ShowPopup(new Discard(_repo));
}
else
{
PopupHost.ShowPopup(new Discard(_repo, changes, true));
}
}
else
{
if (changes.Count == _staged.Count && _unstaged.Count == 0)
{
PopupHost.ShowPopup(new Discard(_repo));
}
else
{
PopupHost.ShowPopup(new Discard(_repo, changes, false));
}
}
}
}
@ -921,24 +913,11 @@ namespace SourceGit.ViewModels
var isUnstaged = _selectedUnstaged != null && _selectedUnstaged.Count > 0;
if (change == null)
{
DetailContext = null;
}
else if (change.IsConflit && isUnstaged)
{
DetailContext = new ConflictContext(_repo.FullPath, change);
}
else
{
if (_detailContext is DiffContext previous)
{
DetailContext = new DiffContext(_repo.FullPath, new Models.DiffOption(change, isUnstaged), previous);
}
else
{
DetailContext = new DiffContext(_repo.FullPath, new Models.DiffOption(change, isUnstaged));
}
}
DetailContext = new DiffContext(_repo.FullPath, new Models.DiffOption(change, isUnstaged), _detailContext as DiffContext);
}
private async void UseTheirs(List<Models.Change> changes)