From a145d6e4c379ce0cce81d1db96ef2ffda2987e7b Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 13 Aug 2024 15:58:34 +0800 Subject: [PATCH] revert: remove issue link support in commit list * improve render performance * the links in commit list are very easy to click by mistake --- src/ViewModels/Histories.cs | 6 -- src/Views/Histories.axaml | 9 +- src/Views/Histories.axaml.cs | 157 ----------------------------------- 3 files changed, 4 insertions(+), 168 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 5a943e04..8f21bf70 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Platform.Storage; using Avalonia.VisualTree; @@ -55,11 +54,6 @@ namespace SourceGit.ViewModels set => SetProperty(ref _detailContext, value); } - public AvaloniaList IssueTrackerRules - { - get => _repo.Settings.IssueTrackerRules; - } - public Histories(Repository repo) { _repo = repo; diff --git a/src/Views/Histories.axaml b/src/Views/Histories.axaml index 91190315..6859d510 100644 --- a/src/Views/Histories.axaml +++ b/src/Views/Histories.axaml @@ -77,11 +77,10 @@ FontSize="10" VerticalAlignment="Center"/> - + diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 33ba0c37..7a3fef28 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -1,17 +1,13 @@ using System; -using System.Collections.Generic; using System.Text; using Avalonia; -using Avalonia.Collections; using Avalonia.Controls; -using Avalonia.Controls.Documents; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Media; using Avalonia.Threading; -using Avalonia.Utilities; using Avalonia.VisualTree; namespace SourceGit.Views @@ -157,149 +153,6 @@ namespace SourceGit.Views private Status _status = Status.Normal; } - public class CommitSubjectPresenter : TextBlock - { - public static readonly StyledProperty SubjectProperty = - AvaloniaProperty.Register(nameof(Subject)); - - public string Subject - { - get => GetValue(SubjectProperty); - set => SetValue(SubjectProperty, value); - } - - public static readonly StyledProperty> IssueTrackerRulesProperty = - AvaloniaProperty.Register>(nameof(IssueTrackerRules)); - - public AvaloniaList IssueTrackerRules - { - get => GetValue(IssueTrackerRulesProperty); - set => SetValue(IssueTrackerRulesProperty, value); - } - - protected override Type StyleKeyOverride => typeof(TextBlock); - - protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) - { - base.OnPropertyChanged(change); - - if (change.Property == SubjectProperty || change.Property == IssueTrackerRulesProperty) - { - Inlines.Clear(); - _matches = null; - ClearHoveredIssueLink(); - - var subject = Subject; - if (string.IsNullOrEmpty(subject)) - return; - - var rules = IssueTrackerRules; - if (rules == null || rules.Count == 0) - { - Inlines.Add(new Run(subject)); - return; - } - - var matches = new List(); - foreach (var rule in rules) - rule.Matches(matches, subject); - - if (matches.Count == 0) - { - Inlines.Add(new Run(subject)); - return; - } - - matches.Sort((l, r) => l.Start - r.Start); - _matches = matches; - - int pos = 0; - foreach (var match in matches) - { - if (match.Start > pos) - Inlines.Add(new Run(subject.Substring(pos, match.Start - pos))); - - match.Link = new Run(subject.Substring(match.Start, match.Length)); - match.Link.Classes.Add("issue_link"); - Inlines.Add(match.Link); - - pos = match.Start + match.Length; - } - - if (pos < subject.Length) - Inlines.Add(new Run(subject.Substring(pos))); - } - } - - protected override void OnPointerMoved(PointerEventArgs e) - { - base.OnPointerMoved(e); - - if (_matches != null) - { - var padding = Padding; - var point = e.GetPosition(this) - new Point(padding.Left, padding.Top); - point = new Point( - MathUtilities.Clamp(point.X, 0, Math.Max(TextLayout.WidthIncludingTrailingWhitespace, 0)), - MathUtilities.Clamp(point.Y, 0, Math.Max(TextLayout.Height, 0))); - - var textPosition = TextLayout.HitTestPoint(point).TextPosition; - foreach (var match in _matches) - { - if (!match.Intersect(textPosition, 1)) - continue; - - if (match == _lastHover) - return; - - _lastHover = match; - _lastHover.Link.Classes.Add("issue_link_hovered"); - - SetCurrentValue(CursorProperty, Cursor.Parse("Hand")); - ToolTip.SetTip(this, match.URL); - ToolTip.SetIsOpen(this, true); - e.Handled = true; - return; - } - - ClearHoveredIssueLink(); - } - } - - protected override void OnPointerPressed(PointerPressedEventArgs e) - { - if (_lastHover != null) - { - Native.OS.OpenBrowser(_lastHover.URL); - ClearHoveredIssueLink(); - e.Handled = true; - return; - } - - base.OnPointerPressed(e); - } - - protected override void OnPointerExited(PointerEventArgs e) - { - base.OnPointerExited(e); - ClearHoveredIssueLink(); - } - - private void ClearHoveredIssueLink() - { - if (_lastHover != null) - { - ToolTip.SetTip(this, null); - SetCurrentValue(CursorProperty, Cursor.Parse("Arrow")); - _lastHover.Link.Classes.Remove("issue_link_hovered"); - _lastHover = null; - } - } - - private List _matches = null; - private Models.IssueTrackerMatch _lastHover = null; - } - public class CommitTimeTextBlock : TextBlock { public static readonly StyledProperty ShowAsDateTimeProperty = @@ -607,16 +460,6 @@ namespace SourceGit.Views set => SetValue(NavigationIdProperty, value); } - public AvaloniaList IssueTrackerRules - { - get - { - if (DataContext is ViewModels.Histories histories) - return histories.IssueTrackerRules; - return null; - } - } - static Histories() { NavigationIdProperty.Changed.AddClassHandler((h, _) =>