Skip to content

Commit 8c1e1a3

Browse files
committed
fix: text diff view scrolling issue introduced by AvaloniaEdit 11.2.0 (commit 7caa03a)
- `SyncScrollOffset` does not update in `side-by-side` mode while scrolling - Highlighted chunk is not cleared when scroll by drag scrollbar Signed-off-by: leo <longshuang@msn.cn>
1 parent 56253e9 commit 8c1e1a3

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

src/Views/TextDiffView.axaml.cs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,6 @@ public void GotoFirstChange()
565565
ScrollToLine(prev.Start);
566566
}
567567
}
568-
// NOTE: Not implemented (button hidden) for non-block navigation.
569568
}
570569

571570
public void GotoPrevChange()
@@ -678,7 +677,6 @@ public void GotoLastChange()
678677
ScrollToLine(next.Start);
679678
}
680679
}
681-
// NOTE: Not implemented (button hidden) for non-block navigation.
682680
}
683681

684682
public override void Render(DrawingContext context)
@@ -1229,15 +1227,15 @@ protected override void OnLoaded(RoutedEventArgs e)
12291227
if (scroller != null)
12301228
{
12311229
scroller.Bind(ScrollViewer.OffsetProperty, new Binding("ScrollOffset", BindingMode.TwoWay));
1232-
scroller.GotFocus += OnTextViewScrollGotFocus;
1230+
scroller.ScrollChanged += OnTextViewScrollChanged;
12331231
}
12341232
}
12351233

12361234
protected override void OnUnloaded(RoutedEventArgs e)
12371235
{
12381236
var scroller = this.FindDescendantOfType<ScrollViewer>();
12391237
if (scroller != null)
1240-
scroller.GotFocus -= OnTextViewScrollGotFocus;
1238+
scroller.ScrollChanged -= OnTextViewScrollChanged;
12411239

12421240
base.OnUnloaded(e);
12431241
}
@@ -1274,9 +1272,9 @@ protected override void OnDataContextChanged(EventArgs e)
12741272
GC.Collect();
12751273
}
12761274

1277-
private void OnTextViewScrollGotFocus(object sender, GotFocusEventArgs e)
1275+
private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e)
12781276
{
1279-
if (EnableChunkSelection && !TextArea.IsPointerOver)
1277+
if (sender is ScrollViewer { IsExpanded: true, IsPointerOver: true } scroller)
12801278
TrySetChunk(null);
12811279
}
12821280
}
@@ -1446,25 +1444,19 @@ protected override void OnLoaded(RoutedEventArgs e)
14461444
_scrollViewer = this.FindDescendantOfType<ScrollViewer>();
14471445
if (_scrollViewer != null)
14481446
{
1449-
_scrollViewer.GotFocus += OnTextViewScrollGotFocus;
14501447
_scrollViewer.ScrollChanged += OnTextViewScrollChanged;
14511448
_scrollViewer.Bind(ScrollViewer.OffsetProperty, new Binding("SyncScrollOffset", BindingMode.OneWay));
14521449
}
1453-
1454-
TextArea.PointerWheelChanged += OnTextAreaPointerWheelChanged;
14551450
}
14561451

14571452
protected override void OnUnloaded(RoutedEventArgs e)
14581453
{
14591454
if (_scrollViewer != null)
14601455
{
14611456
_scrollViewer.ScrollChanged -= OnTextViewScrollChanged;
1462-
_scrollViewer.GotFocus -= OnTextViewScrollGotFocus;
14631457
_scrollViewer = null;
14641458
}
14651459

1466-
TextArea.PointerWheelChanged -= OnTextAreaPointerWheelChanged;
1467-
14681460
base.OnUnloaded(e);
14691461
GC.Collect();
14701462
}
@@ -1499,22 +1491,15 @@ protected override void OnDataContextChanged(EventArgs e)
14991491
}
15001492
}
15011493

1502-
private void OnTextViewScrollGotFocus(object sender, GotFocusEventArgs e)
1503-
{
1504-
if (EnableChunkSelection && !TextArea.IsPointerOver)
1505-
TrySetChunk(null);
1506-
}
1507-
15081494
private void OnTextViewScrollChanged(object sender, ScrollChangedEventArgs e)
15091495
{
1510-
if (TextArea.IsFocused && DataContext is ViewModels.TwoSideTextDiff diff)
1496+
if (IsPointerOver && DataContext is ViewModels.TwoSideTextDiff diff)
1497+
{
15111498
diff.SyncScrollOffset = _scrollViewer?.Offset ?? Vector.Zero;
1512-
}
15131499

1514-
private void OnTextAreaPointerWheelChanged(object sender, PointerWheelEventArgs e)
1515-
{
1516-
if (!TextArea.IsFocused)
1517-
Focus();
1500+
if (sender is ScrollViewer { IsExpanded: true, IsPointerOver: true } scroller )
1501+
TrySetChunk(null);
1502+
}
15181503
}
15191504

15201505
private ScrollViewer _scrollViewer = null;

0 commit comments

Comments
 (0)