mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
refactor: sync scroll implement
This commit is contained in:
parent
ce35a0365d
commit
0c618998b2
3 changed files with 33 additions and 13 deletions
|
@ -5,8 +5,6 @@ using System.Text.RegularExpressions;
|
|||
using Avalonia;
|
||||
using Avalonia.Media.Imaging;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public enum TextDiffLineType
|
||||
|
@ -61,17 +59,12 @@ namespace SourceGit.Models
|
|||
}
|
||||
}
|
||||
|
||||
public partial class TextDiff : ObservableObject
|
||||
public partial class TextDiff
|
||||
{
|
||||
public string File { get; set; } = string.Empty;
|
||||
public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>();
|
||||
public int MaxLineNumber = 0;
|
||||
|
||||
private Vector _syncScrollOffset = Vector.Zero;
|
||||
public Vector SyncScrollOffset {
|
||||
get => _syncScrollOffset;
|
||||
set => SetProperty(ref _syncScrollOffset, value);
|
||||
}
|
||||
public Vector SyncScrollOffset = Vector.Zero;
|
||||
|
||||
public void GenerateNewPatchFromSelection(Change change, string fileBlobGuid, TextDiffSelection selection, bool revert, string output)
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
SecondaryFG="{DynamicResource Brush.FG2}"
|
||||
FontFamily="{Binding Source={x:Static vm:Preference.Instance}, Path=MonospaceFont}"
|
||||
DiffData="{Binding}"
|
||||
SyncScrollOffset="{Binding #ThisControl.TextDiff.SyncScrollOffset, Mode=TwoWay}"
|
||||
SyncScrollOffset="{Binding #ThisControl.SyncScrollOffset, Mode=TwoWay}"
|
||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"/>
|
||||
</DataTemplate>
|
||||
|
@ -25,7 +25,7 @@
|
|||
<DataTemplate DataType="vm:TwoSideTextDiff">
|
||||
<Grid ColumnDefinitions="*,1,*">
|
||||
<v:SingleSideTextDiffPresenter Grid.Column="0"
|
||||
SyncScrollOffset="{Binding #ThisControl.TextDiff.SyncScrollOffset, Mode=TwoWay}"
|
||||
SyncScrollOffset="{Binding #ThisControl.SyncScrollOffset, Mode=TwoWay}"
|
||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||
IsOld="True"
|
||||
|
@ -39,7 +39,7 @@
|
|||
<Rectangle Grid.Column="1" Fill="{DynamicResource Brush.Border2}" Width="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
|
||||
|
||||
<v:SingleSideTextDiffPresenter Grid.Column="2"
|
||||
SyncScrollOffset="{Binding #ThisControl.TextDiff.SyncScrollOffset, Mode=TwoWay}"
|
||||
SyncScrollOffset="{Binding #ThisControl.SyncScrollOffset, Mode=TwoWay}"
|
||||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||
IsOld="False"
|
||||
|
|
|
@ -840,6 +840,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(UseSideBySideDiffProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<Vector> SyncScrollOffsetProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, Vector>(nameof(SyncScrollOffset));
|
||||
|
||||
public Vector SyncScrollOffset
|
||||
{
|
||||
get => GetValue(SyncScrollOffsetProperty);
|
||||
set => SetValue(SyncScrollOffsetProperty, value);
|
||||
}
|
||||
|
||||
public TextDiffView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -1081,7 +1090,7 @@ namespace SourceGit.Views
|
|||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (change.Property == TextDiffProperty || change.Property == UseSideBySideDiffProperty)
|
||||
if (change.Property == TextDiffProperty)
|
||||
{
|
||||
if (TextDiff == null)
|
||||
{
|
||||
|
@ -1090,12 +1099,30 @@ namespace SourceGit.Views
|
|||
else if (UseSideBySideDiff)
|
||||
{
|
||||
Content = new ViewModels.TwoSideTextDiff(TextDiff);
|
||||
SyncScrollOffset = TextDiff.SyncScrollOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
Content = TextDiff;
|
||||
SyncScrollOffset = TextDiff.SyncScrollOffset;
|
||||
}
|
||||
}
|
||||
else if (change.Property == UseSideBySideDiffProperty)
|
||||
{
|
||||
SyncScrollOffset = Vector.Zero;
|
||||
|
||||
if (TextDiff == null)
|
||||
Content = null;
|
||||
else if (UseSideBySideDiff)
|
||||
Content = new ViewModels.TwoSideTextDiff(TextDiff);
|
||||
else
|
||||
Content = TextDiff;
|
||||
}
|
||||
else if (change.Property == SyncScrollOffsetProperty)
|
||||
{
|
||||
if (TextDiff != null)
|
||||
TextDiff.SyncScrollOffset = SyncScrollOffset;
|
||||
}
|
||||
}
|
||||
|
||||
private Models.TextDiffSelection GetUnifiedSelection(int startLine, int endLine, bool isOldSide)
|
||||
|
|
Loading…
Reference in a new issue