ux: change cursor to Hand when hover a commit hash link (#522)

This commit is contained in:
leo 2024-09-28 11:25:17 +08:00
parent bb907deddb
commit 841a009a56
No known key found for this signature in database
2 changed files with 44 additions and 2 deletions

View file

@ -33,7 +33,7 @@ namespace SourceGit.Views
return;
var view = TextView;
if (view != null && view.VisualLinesValid)
if (view is { VisualLinesValid: true })
{
var typeface = view.CreateTypeface();
var underlinePen = new Pen(Brushes.DarkOrange);
@ -142,12 +142,53 @@ namespace SourceGit.Views
return new Size(maxWidth, 0);
}
protected override void OnPointerMoved(PointerEventArgs e)
{
base.OnPointerMoved(e);
var view = TextView;
if (!e.Handled && view is { VisualLinesValid: true })
{
var pos = e.GetPosition(this);
var typeface = view.CreateTypeface();
foreach (var line in view.VisualLines)
{
if (line.IsDisposed || line.FirstDocumentLine == null || line.FirstDocumentLine.IsDeleted)
continue;
var lineNumber = line.FirstDocumentLine.LineNumber;
if (lineNumber >= _editor.BlameData.LineInfos.Count)
break;
var info = _editor.BlameData.LineInfos[lineNumber - 1];
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - view.VerticalOffset;
var shaLink = new FormattedText(
info.CommitSHA,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
typeface,
_editor.FontSize,
Brushes.DarkOrange);
var rect = new Rect(0, y, shaLink.Width, shaLink.Height);
if (rect.Contains(pos))
{
Cursor = Cursor.Parse("Hand");
return;
}
}
}
Cursor = Cursor.Default;
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
base.OnPointerPressed(e);
var view = TextView;
if (!e.Handled && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed && view != null && view.VisualLinesValid)
if (!e.Handled && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed && view is { VisualLinesValid: true })
{
var pos = e.GetPosition(this);
var typeface = view.CreateTypeface();

View file

@ -87,6 +87,7 @@
<TextBlock Grid.Column="2"
Classes="primary"
Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
Cursor="Hand"
Background="Transparent"
Foreground="DarkOrange"
TextDecorations="Underline"