From acd61713500c38ee7bda7eae6c3b95e6264c1671 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 9 Sep 2024 12:22:26 +0800 Subject: [PATCH] refactor: remove `Caret.PositionChanged` event listener since `TextArea.LayoutUpdated` will also triggered when caret position changed (#448) --- src/Views/Blame.axaml.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Views/Blame.axaml.cs b/src/Views/Blame.axaml.cs index 322d94c7..a0b3c810 100644 --- a/src/Views/Blame.axaml.cs +++ b/src/Views/Blame.axaml.cs @@ -234,7 +234,6 @@ namespace SourceGit.Views TextArea.LeftMargins.Add(new CommitInfoMargin(this) { Margin = new Thickness(8, 0) }); TextArea.LeftMargins.Add(new VerticalSeperatorMargin(this)); TextArea.LayoutUpdated += OnTextAreaLayoutUpdated; - TextArea.Caret.PositionChanged += OnCaretPositionChanged; TextArea.TextView.ContextRequested += OnTextViewContextRequested; TextArea.TextView.VisualLinesChanged += OnTextViewVisualLinesChanged; TextArea.TextView.Margin = new Thickness(4, 0); @@ -279,8 +278,7 @@ namespace SourceGit.Views base.OnUnloaded(e); TextArea.LeftMargins.Clear(); - TextArea.LayoutUpdated += OnTextAreaLayoutUpdated; - TextArea.Caret.PositionChanged -= OnCaretPositionChanged; + TextArea.LayoutUpdated -= OnTextAreaLayoutUpdated; TextArea.TextView.ContextRequested -= OnTextViewContextRequested; TextArea.TextView.VisualLinesChanged -= OnTextViewVisualLinesChanged; @@ -314,17 +312,12 @@ namespace SourceGit.Views } private void OnTextAreaLayoutUpdated(object sender, EventArgs e) - { - InvalidateVisual(); - } - - private void OnCaretPositionChanged(object sender, EventArgs e) { if (!TextArea.IsFocused) return; var caret = TextArea.Caret; - if (caret.Line >= BlameData.LineInfos.Count) + if (caret == null || caret.Line >= BlameData.LineInfos.Count) return; var info = BlameData.LineInfos[caret.Line - 1]; @@ -332,7 +325,12 @@ namespace SourceGit.Views { _highlight = info.CommitSHA; InvalidateVisual(); + return; } + + var offset = TextArea.TextView.VerticalOffset; + if (_lastOffsetY != offset) + InvalidateVisual(); } private void OnTextViewContextRequested(object sender, ContextRequestedEventArgs e) @@ -380,6 +378,7 @@ namespace SourceGit.Views private TextMate.Installation _textMate = null; private string _highlight = string.Empty; + private double _lastOffsetY = 0; } public partial class Blame : ChromelessWindow