refactor: use bindings instead of sync manually

This commit is contained in:
leo 2024-06-06 10:01:14 +08:00
parent e432559a5e
commit 54ef9c0bf7
No known key found for this signature in database
GPG key ID: B528468E49CD0E58
3 changed files with 2 additions and 14 deletions

View file

@ -63,8 +63,8 @@ namespace SourceGit.Models
{ {
public string File { get; set; } = string.Empty; public string File { get; set; } = string.Empty;
public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>(); public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>();
public Vector SyncScrollOffset { get; set; } = Vector.Zero;
public int MaxLineNumber = 0; public int MaxLineNumber = 0;
public Vector SyncScrollOffset = Vector.Zero;
public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output) public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output)
{ {

View file

@ -224,6 +224,7 @@
<!-- Text Diff --> <!-- Text Diff -->
<DataTemplate DataType="m:TextDiff"> <DataTemplate DataType="m:TextDiff">
<v:TextDiffView TextDiff="{Binding}" <v:TextDiffView TextDiff="{Binding}"
SyncScrollOffset="{Binding SyncScrollOffset, Mode=TwoWay}"
UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"/> UseSideBySideDiff="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSideBySideDiff, Mode=OneWay}"/>
</DataTemplate> </DataTemplate>

View file

@ -1169,19 +1169,11 @@ namespace SourceGit.Views
if (change.Property == TextDiffProperty) if (change.Property == TextDiffProperty)
{ {
if (TextDiff == null) if (TextDiff == null)
{
Content = null; Content = null;
}
else if (UseSideBySideDiff) else if (UseSideBySideDiff)
{
Content = new ViewModels.TwoSideTextDiff(TextDiff); Content = new ViewModels.TwoSideTextDiff(TextDiff);
SyncScrollOffset = TextDiff.SyncScrollOffset;
}
else else
{
Content = TextDiff; Content = TextDiff;
SyncScrollOffset = TextDiff.SyncScrollOffset;
}
} }
else if (change.Property == UseSideBySideDiffProperty) else if (change.Property == UseSideBySideDiffProperty)
{ {
@ -1194,11 +1186,6 @@ namespace SourceGit.Views
else else
Content = TextDiff; Content = TextDiff;
} }
else if (change.Property == SyncScrollOffsetProperty)
{
if (TextDiff != null)
TextDiff.SyncScrollOffset = SyncScrollOffset;
}
} }
private Models.TextDiffSelection GetUnifiedSelection(int startLine, int endLine, bool isOldSide) private Models.TextDiffSelection GetUnifiedSelection(int startLine, int endLine, bool isOldSide)