From 245de9b4583f499c3e1b6e8c176e9f9fc3d48932 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 14 Apr 2025 10:40:24 +0800 Subject: [PATCH] fix: tooltip did not hide after pointer move out (#1178) Signed-off-by: leo --- src/Views/Blame.axaml | 9 +++++++- src/Views/Blame.axaml.cs | 3 +-- src/Views/CommitBaseInfo.axaml | 14 +++++++++++++ src/Views/CommitBaseInfo.axaml.cs | 5 ----- src/Views/CommitMessagePresenter.cs | 32 ++++++++++++++++------------- src/Views/CommitSubjectPresenter.cs | 1 - 6 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/Views/Blame.axaml b/src/Views/Blame.axaml index eaad985a..7a3d7ddf 100644 --- a/src/Views/Blame.axaml +++ b/src/Views/Blame.axaml @@ -59,7 +59,14 @@ FontFamily="{DynamicResource Fonts.Monospace}" FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}" TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}" - BlameData="{Binding Data}"/> + BlameData="{Binding Data}"> + + + + + + + + + + + + + + @@ -152,6 +159,13 @@ PointerEntered="OnSHAPointerEntered" PointerPressed="OnSHAPressed" ToolTip.ShowDelay="0"> + + + + + + + diff --git a/src/Views/CommitBaseInfo.axaml.cs b/src/Views/CommitBaseInfo.axaml.cs index 8767db9f..ac9b53cc 100644 --- a/src/Views/CommitBaseInfo.axaml.cs +++ b/src/Views/CommitBaseInfo.axaml.cs @@ -133,12 +133,7 @@ namespace SourceGit.Views Dispatcher.UIThread.Invoke(() => { if (ctl.IsEffectivelyVisible && ctl.DataContext is string newSHA && newSHA == sha) - { ToolTip.SetTip(ctl, c); - - if (ctl.IsPointerOver) - ToolTip.SetIsOpen(ctl, true); - } }); }); } diff --git a/src/Views/CommitMessagePresenter.cs b/src/Views/CommitMessagePresenter.cs index 002beda1..6f838509 100644 --- a/src/Views/CommitMessagePresenter.cs +++ b/src/Views/CommitMessagePresenter.cs @@ -5,6 +5,8 @@ using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Documents; +using Avalonia.Data; +using Avalonia.Data.Converters; using Avalonia.Input; using Avalonia.Threading; using Avalonia.VisualTree; @@ -24,6 +26,21 @@ namespace SourceGit.Views protected override Type StyleKeyOverride => typeof(SelectableTextBlock); + public CommitMessagePresenter() + { + var bindings = new MultiBinding() + { + Converter = BoolConverters.And, + Bindings = new[] + { + new Binding() { Path = "IsPointerOver", Source = this }, + new Binding() { Path = "(ToolTip.Tip)", Source = this, TypeResolver = (_, name) => name == "ToolTip" ? typeof(ToolTip) : null, Converter = ObjectConverters.IsNotNull }, + } + }; + + Bind(ToolTip.IsOpenProperty, bindings); + } + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) { base.OnPropertyChanged(change); @@ -107,14 +124,9 @@ namespace SourceGit.Views _lastHover = link; if (!link.IsCommitSHA) - { ToolTip.SetTip(this, link.Link); - ToolTip.SetIsOpen(this, true); - } else - { ProcessHoverCommitLink(link); - } return; } @@ -264,12 +276,7 @@ namespace SourceGit.Views // If we have already queried this SHA, just use it. if (_inlineCommits.TryGetValue(sha, out var exist)) { - if (exist != null) - { - ToolTip.SetTip(this, exist); - ToolTip.SetIsOpen(this, true); - } - + ToolTip.SetTip(this, exist); return; } @@ -294,10 +301,7 @@ namespace SourceGit.Views // Make sure user still hovers the target SHA. if (_lastHover == link && c != null) - { ToolTip.SetTip(this, c); - ToolTip.SetIsOpen(this, true); - } } }); }); diff --git a/src/Views/CommitSubjectPresenter.cs b/src/Views/CommitSubjectPresenter.cs index 32f6838d..83d79fe4 100644 --- a/src/Views/CommitSubjectPresenter.cs +++ b/src/Views/CommitSubjectPresenter.cs @@ -144,7 +144,6 @@ namespace SourceGit.Views _lastHover = match; SetCurrentValue(CursorProperty, Cursor.Parse("Hand")); ToolTip.SetTip(this, match.Link); - ToolTip.SetIsOpen(this, true); e.Handled = true; return; }