fix: tooltip did not hide after pointer move out (#1178)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-14 10:40:24 +08:00
parent e76328ff38
commit 245de9b458
No known key found for this signature in database
6 changed files with 41 additions and 23 deletions

View file

@ -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);
}
}
});
});