enhance: avoid flicker at the first time clicking on text diff view

This commit is contained in:
leo 2024-09-29 14:16:42 +08:00
parent d5671ea8df
commit 3af30f54b6
No known key found for this signature in database

View file

@ -694,18 +694,6 @@ namespace SourceGit.Views
return 0;
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
var scroller = (ScrollViewer)e.NameScope.Find("PART_ScrollViewer");
if (scroller != null)
{
scroller.Bind(ScrollViewer.OffsetProperty, new Binding("SyncScrollOffset", BindingMode.TwoWay));
scroller.GotFocus += (_, _) => TrySetChunk(null);
}
}
public override void UpdateSelectedChunk(double y)
{
var diff = DataContext as Models.TextDiff;
@ -822,6 +810,27 @@ namespace SourceGit.Views
}
}
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
var scroller = this.FindDescendantOfType<ScrollViewer>();
if (scroller != null)
{
scroller.Bind(ScrollViewer.OffsetProperty, new Binding("SyncScrollOffset", BindingMode.TwoWay));
scroller.GotFocus += OnTextViewScrollGotFocus;
}
}
protected override void OnUnloaded(RoutedEventArgs e)
{
var scroller = this.FindDescendantOfType<ScrollViewer>();
if (scroller != null)
scroller.GotFocus -= OnTextViewScrollGotFocus;
base.OnUnloaded(e);
}
protected override void OnDataContextChanged(EventArgs e)
{
base.OnDataContextChanged(e);
@ -853,6 +862,16 @@ namespace SourceGit.Views
GC.Collect();
}
private void OnTextViewScrollGotFocus(object sender, GotFocusEventArgs e)
{
if (EnableChunkSelection && sender is ScrollViewer viewer)
{
var area = viewer.FindDescendantOfType<TextArea>();
if (!area.IsPointerOver)
TrySetChunk(null);
}
}
}
public class SingleSideTextDiffPresenter : ThemedTextDiffPresenter
@ -1021,8 +1040,6 @@ namespace SourceGit.Views
protected override void OnUnloaded(RoutedEventArgs e)
{
base.OnUnloaded(e);
if (_scrollViewer != null)
{
_scrollViewer.ScrollChanged -= OnTextViewScrollChanged;
@ -1032,6 +1049,7 @@ namespace SourceGit.Views
TextArea.PointerWheelChanged -= OnTextAreaPointerWheelChanged;
base.OnUnloaded(e);
GC.Collect();
}
@ -1067,8 +1085,13 @@ namespace SourceGit.Views
private void OnTextViewScrollGotFocus(object sender, GotFocusEventArgs e)
{
if (EnableChunkSelection && sender is ScrollViewer viewer)
{
var area = viewer.FindDescendantOfType<TextArea>();
if (!area.IsPointerOver)
TrySetChunk(null);
}
}
private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e)
{