mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: only trigger UpdateSelectedChunk
if needed
This commit is contained in:
parent
5b95344453
commit
91801cff69
3 changed files with 26 additions and 15 deletions
|
@ -20,17 +20,10 @@ namespace SourceGit.ViewModels
|
|||
set => SetProperty(ref _syncScrollOffset, value);
|
||||
}
|
||||
|
||||
public Models.DiffOption Option
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public TwoSideTextDiff(Models.TextDiff diff, TwoSideTextDiff previous = null)
|
||||
{
|
||||
File = diff.File;
|
||||
MaxLineNumber = diff.MaxLineNumber;
|
||||
Option = diff.Option;
|
||||
|
||||
foreach (var line in diff.Lines)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
|
||||
</DataTemplate>
|
||||
|
||||
|
@ -46,6 +47,7 @@
|
|||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
|
||||
|
||||
<Rectangle Grid.Column="1" Fill="{DynamicResource Brush.Border2}" Width="1" HorizontalAlignment="Center" VerticalAlignment="Stretch"/>
|
||||
|
@ -65,6 +67,7 @@
|
|||
UseSyntaxHighlighting="{Binding Source={x:Static vm:Preference.Instance}, Path=UseSyntaxHighlighting}"
|
||||
WordWrap="{Binding Source={x:Static vm:Preference.Instance}, Path=EnableDiffViewWordWrap}"
|
||||
ShowHiddenSymbols="{Binding Source={x:Static vm:Preference.Instance}, Path=ShowHiddenSymbolsInDiffView}"
|
||||
EnableChunkSelection="{Binding #ThisControl.EnableChunkSelection}"
|
||||
SelectedChunk="{Binding #ThisControl.SelectedChunk, Mode=TwoWay}"/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
|
|
@ -336,6 +336,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(ShowHiddenSymbolsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> EnableChunkSelectionProperty =
|
||||
AvaloniaProperty.Register<ThemedTextDiffPresenter, bool>(nameof(EnableChunkSelection));
|
||||
|
||||
public bool EnableChunkSelection
|
||||
{
|
||||
get => GetValue(EnableChunkSelectionProperty);
|
||||
set => SetValue(EnableChunkSelectionProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<TextDiffViewChunk> SelectedChunkProperty =
|
||||
AvaloniaProperty.Register<ThemedTextDiffPresenter, TextDiffViewChunk>(nameof(SelectedChunk));
|
||||
|
||||
|
@ -479,13 +488,13 @@ namespace SourceGit.Views
|
|||
|
||||
private void OnTextViewPointerMoved(object sender, PointerEventArgs e)
|
||||
{
|
||||
if (sender is TextView view)
|
||||
if (EnableChunkSelection && sender is TextView view)
|
||||
UpdateSelectedChunk(e.GetPosition(view).Y + view.VerticalOffset);
|
||||
}
|
||||
|
||||
private void OnTextViewPointerWheelChanged(object sender, PointerWheelEventArgs e)
|
||||
{
|
||||
if (sender is TextView view)
|
||||
if (EnableChunkSelection && sender is TextView view)
|
||||
{
|
||||
var y = e.GetPosition(view).Y + view.VerticalOffset;
|
||||
Dispatcher.UIThread.Post(() => UpdateSelectedChunk(y));
|
||||
|
@ -636,7 +645,7 @@ namespace SourceGit.Views
|
|||
public override void UpdateSelectedChunk(double y)
|
||||
{
|
||||
var diff = DataContext as Models.TextDiff;
|
||||
if (diff == null || diff.Option.WorkingCopyChange == null)
|
||||
if (diff == null)
|
||||
return;
|
||||
|
||||
var view = TextArea.TextView;
|
||||
|
@ -796,7 +805,7 @@ namespace SourceGit.Views
|
|||
public override void UpdateSelectedChunk(double y)
|
||||
{
|
||||
var diff = DataContext as ViewModels.TwoSideTextDiff;
|
||||
if (diff == null || diff.Option.WorkingCopyChange == null)
|
||||
if (diff == null)
|
||||
return;
|
||||
|
||||
var parent = this.FindAncestorOfType<TextDiffView>();
|
||||
|
@ -1012,6 +1021,15 @@ namespace SourceGit.Views
|
|||
set => SetValue(IsUnstagedChangeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<bool> EnableChunkSelectionProperty =
|
||||
AvaloniaProperty.Register<TextDiffView, bool>(nameof(EnableChunkSelection));
|
||||
|
||||
public bool EnableChunkSelection
|
||||
{
|
||||
get => GetValue(EnableChunkSelectionProperty);
|
||||
set => SetValue(EnableChunkSelectionProperty, value);
|
||||
}
|
||||
|
||||
static TextDiffView()
|
||||
{
|
||||
UseSideBySideDiffProperty.Changed.AddClassHandler<TextDiffView>((v, _) =>
|
||||
|
@ -1069,6 +1087,7 @@ namespace SourceGit.Views
|
|||
Editor.Content = diff;
|
||||
|
||||
IsUnstagedChange = diff.Option.IsUnstaged;
|
||||
EnableChunkSelection = diff.Option.WorkingCopyChange != null;
|
||||
}
|
||||
|
||||
protected override void OnPointerExited(PointerEventArgs e)
|
||||
|
@ -1160,8 +1179,6 @@ namespace SourceGit.Views
|
|||
if (!selection.HasChanges)
|
||||
return;
|
||||
|
||||
// If all changes has been selected the use method provided by ViewModels.WorkingCopy.
|
||||
// Otherwise, use `git apply`
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
var workcopyView = this.FindAncestorOfType<WorkingCopy>();
|
||||
|
@ -1218,8 +1235,6 @@ namespace SourceGit.Views
|
|||
if (!selection.HasChanges)
|
||||
return;
|
||||
|
||||
// If all changes has been selected the use method provided by ViewModels.WorkingCopy.
|
||||
// Otherwise, use `git apply`
|
||||
if (!selection.HasLeftChanges)
|
||||
{
|
||||
var workcopyView = this.FindAncestorOfType<WorkingCopy>();
|
||||
|
|
Loading…
Reference in a new issue