diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 6ae637fc..dd3471bf 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -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(); + 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(); + 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