refactor: move some method from view to its data source class

This commit is contained in:
leo 2024-07-18 11:40:56 +08:00
parent e64026d44c
commit dbc95e7209
No known key found for this signature in database
3 changed files with 126 additions and 127 deletions

View file

@ -1,5 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Avalonia;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
@ -53,6 +56,45 @@ namespace SourceGit.ViewModels
_syncScrollOffset = previous._syncScrollOffset;
}
public void ConvertsToCombinedRange(Models.TextDiff combined, ref int startLine, ref int endLine, bool isOldSide)
{
endLine = Math.Min(endLine, combined.Lines.Count);
var oneSide = isOldSide ? Old : New;
var firstContentLine = -1;
for (int i = startLine - 1; i < endLine; i++)
{
var line = oneSide[i];
if (line.Type != Models.TextDiffLineType.None)
{
firstContentLine = i;
break;
}
}
if (firstContentLine < 0)
return;
var endContentLine = -1;
for (int i = Math.Min(endLine - 1, oneSide.Count - 1); i >= startLine - 1; i--)
{
var line = oneSide[i];
if (line.Type != Models.TextDiffLineType.None)
{
endContentLine = i;
break;
}
}
if (endContentLine < 0)
return;
var firstContent = oneSide[firstContentLine];
var endContent = oneSide[endContentLine];
startLine = combined.Lines.IndexOf(firstContent) + 1;
endLine = combined.Lines.IndexOf(endContent) + 1;
}
private void FillEmptyLines()
{
if (Old.Count < New.Count)