Skip to content

Commit 841a009

Browse files
committed
ux: change cursor to Hand when hover a commit hash link (#522)
1 parent bb907de commit 841a009

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Views/Blame.axaml.cs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override void Render(DrawingContext context)
3333
return;
3434

3535
var view = TextView;
36-
if (view != null && view.VisualLinesValid)
36+
if (view is { VisualLinesValid: true })
3737
{
3838
var typeface = view.CreateTypeface();
3939
var underlinePen = new Pen(Brushes.DarkOrange);
@@ -142,12 +142,53 @@ protected override Size MeasureOverride(Size availableSize)
142142
return new Size(maxWidth, 0);
143143
}
144144

145+
protected override void OnPointerMoved(PointerEventArgs e)
146+
{
147+
base.OnPointerMoved(e);
148+
149+
var view = TextView;
150+
if (!e.Handled && view is { VisualLinesValid: true })
151+
{
152+
var pos = e.GetPosition(this);
153+
var typeface = view.CreateTypeface();
154+
155+
foreach (var line in view.VisualLines)
156+
{
157+
if (line.IsDisposed || line.FirstDocumentLine == null || line.FirstDocumentLine.IsDeleted)
158+
continue;
159+
160+
var lineNumber = line.FirstDocumentLine.LineNumber;
161+
if (lineNumber >= _editor.BlameData.LineInfos.Count)
162+
break;
163+
164+
var info = _editor.BlameData.LineInfos[lineNumber - 1];
165+
var y = line.GetTextLineVisualYPosition(line.TextLines[0], VisualYPosition.TextTop) - view.VerticalOffset;
166+
var shaLink = new FormattedText(
167+
info.CommitSHA,
168+
CultureInfo.CurrentCulture,
169+
FlowDirection.LeftToRight,
170+
typeface,
171+
_editor.FontSize,
172+
Brushes.DarkOrange);
173+
174+
var rect = new Rect(0, y, shaLink.Width, shaLink.Height);
175+
if (rect.Contains(pos))
176+
{
177+
Cursor = Cursor.Parse("Hand");
178+
return;
179+
}
180+
}
181+
}
182+
183+
Cursor = Cursor.Default;
184+
}
185+
145186
protected override void OnPointerPressed(PointerPressedEventArgs e)
146187
{
147188
base.OnPointerPressed(e);
148189

149190
var view = TextView;
150-
if (!e.Handled && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed && view != null && view.VisualLinesValid)
191+
if (!e.Handled && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed && view is { VisualLinesValid: true })
151192
{
152193
var pos = e.GetPosition(this);
153194
var typeface = view.CreateTypeface();

src/Views/FileHistories.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
<TextBlock Grid.Column="2"
8888
Classes="primary"
8989
Text="{Binding SHA, Converter={x:Static c:StringConverters.ToShortSHA}}"
90+
Cursor="Hand"
9091
Background="Transparent"
9192
Foreground="DarkOrange"
9293
TextDecorations="Underline"

0 commit comments

Comments
 (0)