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

@ -59,7 +59,14 @@
FontFamily="{DynamicResource Fonts.Monospace}" FontFamily="{DynamicResource Fonts.Monospace}"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}" FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}" TabWidth="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorTabWidth}"
BlameData="{Binding Data}"/> BlameData="{Binding Data}">
<ToolTip.IsOpen>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="$self.IsPointerOver"/>
<Binding Path="$self.(ToolTip.Tip)" Converter="{x:Static ObjectConverters.IsNotNull}"/>
</MultiBinding>
</ToolTip.IsOpen>
</v:BlameTextEditor>
<!-- Not supported mask (for binary files) --> <!-- Not supported mask (for binary files) -->
<StackPanel Orientation="Vertical" <StackPanel Orientation="Vertical"

View file

@ -180,7 +180,6 @@ namespace SourceGit.Views
{ {
var msg = blame.GetCommitMessage(info.CommitSHA); var msg = blame.GetCommitMessage(info.CommitSHA);
ToolTip.SetTip(this, msg); ToolTip.SetTip(this, msg);
ToolTip.SetIsOpen(this, true);
} }
return; return;
@ -188,7 +187,7 @@ namespace SourceGit.Views
} }
Cursor = Cursor.Default; Cursor = Cursor.Default;
ToolTip.SetIsOpen(this, false); ToolTip.SetTip(this, null);
} }
} }

View file

@ -114,6 +114,13 @@
PointerEntered="OnSHAPointerEntered" PointerEntered="OnSHAPointerEntered"
PointerPressed="OnSHAPressed" PointerPressed="OnSHAPressed"
ToolTip.ShowDelay="0"> ToolTip.ShowDelay="0">
<ToolTip.IsOpen>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="$self.IsPointerOver"/>
<Binding Path="$self.(ToolTip.Tip)" Converter="{x:Static ObjectConverters.IsNotNull}"/>
</MultiBinding>
</ToolTip.IsOpen>
<TextBlock.DataTemplates> <TextBlock.DataTemplates>
<DataTemplate DataType="m:Commit"> <DataTemplate DataType="m:Commit">
<StackPanel MinWidth="400" Orientation="Vertical"> <StackPanel MinWidth="400" Orientation="Vertical">
@ -152,6 +159,13 @@
PointerEntered="OnSHAPointerEntered" PointerEntered="OnSHAPointerEntered"
PointerPressed="OnSHAPressed" PointerPressed="OnSHAPressed"
ToolTip.ShowDelay="0"> ToolTip.ShowDelay="0">
<ToolTip.IsOpen>
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding Path="$self.IsPointerOver"/>
<Binding Path="$self.(ToolTip.Tip)" Converter="{x:Static ObjectConverters.IsNotNull}"/>
</MultiBinding>
</ToolTip.IsOpen>
<TextBlock.DataTemplates> <TextBlock.DataTemplates>
<DataTemplate DataType="m:Commit"> <DataTemplate DataType="m:Commit">
<StackPanel MinWidth="400" Orientation="Vertical"> <StackPanel MinWidth="400" Orientation="Vertical">

View file

@ -133,12 +133,7 @@ namespace SourceGit.Views
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
if (ctl.IsEffectivelyVisible && ctl.DataContext is string newSHA && newSHA == sha) if (ctl.IsEffectivelyVisible && ctl.DataContext is string newSHA && newSHA == sha)
{
ToolTip.SetTip(ctl, c); ToolTip.SetTip(ctl, c);
if (ctl.IsPointerOver)
ToolTip.SetIsOpen(ctl, true);
}
}); });
}); });
} }

View file

@ -5,6 +5,8 @@ using System.Threading.Tasks;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Documents; using Avalonia.Controls.Documents;
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Threading; using Avalonia.Threading;
using Avalonia.VisualTree; using Avalonia.VisualTree;
@ -24,6 +26,21 @@ namespace SourceGit.Views
protected override Type StyleKeyOverride => typeof(SelectableTextBlock); 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) protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{ {
base.OnPropertyChanged(change); base.OnPropertyChanged(change);
@ -107,14 +124,9 @@ namespace SourceGit.Views
_lastHover = link; _lastHover = link;
if (!link.IsCommitSHA) if (!link.IsCommitSHA)
{
ToolTip.SetTip(this, link.Link); ToolTip.SetTip(this, link.Link);
ToolTip.SetIsOpen(this, true);
}
else else
{
ProcessHoverCommitLink(link); ProcessHoverCommitLink(link);
}
return; return;
} }
@ -264,12 +276,7 @@ namespace SourceGit.Views
// If we have already queried this SHA, just use it. // If we have already queried this SHA, just use it.
if (_inlineCommits.TryGetValue(sha, out var exist)) if (_inlineCommits.TryGetValue(sha, out var exist))
{ {
if (exist != null) ToolTip.SetTip(this, exist);
{
ToolTip.SetTip(this, exist);
ToolTip.SetIsOpen(this, true);
}
return; return;
} }
@ -294,10 +301,7 @@ namespace SourceGit.Views
// Make sure user still hovers the target SHA. // Make sure user still hovers the target SHA.
if (_lastHover == link && c != null) if (_lastHover == link && c != null)
{
ToolTip.SetTip(this, c); ToolTip.SetTip(this, c);
ToolTip.SetIsOpen(this, true);
}
} }
}); });
}); });

View file

@ -144,7 +144,6 @@ namespace SourceGit.Views
_lastHover = match; _lastHover = match;
SetCurrentValue(CursorProperty, Cursor.Parse("Hand")); SetCurrentValue(CursorProperty, Cursor.Parse("Hand"));
ToolTip.SetTip(this, match.Link); ToolTip.SetTip(this, match.Link);
ToolTip.SetIsOpen(this, true);
e.Handled = true; e.Handled = true;
return; return;
} }