Skip to content

Commit 12efd85

Browse files
committed
ux: use monospace font for inline code in commit message
Signed-off-by: leo <[email protected]>
1 parent a035e62 commit 12efd85

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/Resources/Styles.axaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,10 @@
532532
<Setter Property="Foreground" Value="DarkOrange"/>
533533
<Setter Property="TextDecorations" Value="Underline"/>
534534
</Style>
535+
<Style Selector="Run.inline_code">
536+
<Setter Property="FontFamily" Value="{DynamicResource Fonts.Monospace}"/>
537+
<Setter Property="Foreground" Value="{DynamicResource Brush.InlineCodeFG}"/>
538+
</Style>
535539

536540
<Style Selector="SelectableTextBlock">
537541
<Setter Property="HorizontalAlignment" Value="Left"/>

src/Resources/Themes.axaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Color x:Key="Color.Diff.DeletedHighlight">#F19B9D</Color>
2727
<Color x:Key="Color.Link">#0000EE</Color>
2828
<Color x:Key="Color.InlineCode">#FFE4E4E4</Color>
29+
<Color x:Key="Color.InlineCodeFG">Black</Color>
2930
</ResourceDictionary>
3031

3132
<ResourceDictionary x:Key="Dark">
@@ -53,6 +54,7 @@
5354
<Color x:Key="Color.Diff.DeletedHighlight">#A09F4247</Color>
5455
<Color x:Key="Color.Link">#4DAAFC</Color>
5556
<Color x:Key="Color.InlineCode">#FF383838</Color>
57+
<Color x:Key="Color.InlineCodeFG">#FFF0F0F0</Color>
5658
</ResourceDictionary>
5759
</ResourceDictionary.ThemeDictionaries>
5860

@@ -82,6 +84,7 @@
8284
<SolidColorBrush x:Key="Brush.Diff.DeletedHighlight" Color="{DynamicResource Color.Diff.DeletedHighlight}"/>
8385
<SolidColorBrush x:Key="Brush.Link" Color="{DynamicResource Color.Link}"/>
8486
<SolidColorBrush x:Key="Brush.InlineCode" Color="{DynamicResource Color.InlineCode}"/>
87+
<SolidColorBrush x:Key="Brush.InlineCodeFG" Color="{DynamicResource Color.InlineCodeFG}"/>
8588

8689
<FontFamily x:Key="Fonts.Default">fonts:Inter#Inter</FontFamily>
8790
<FontFamily x:Key="Fonts.Monospace">fonts:SourceGit#JetBrains Mono</FontFamily>

src/ViewModels/CommitDetail.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,17 @@ private void Refresh()
485485
inlines.Add(new Models.InlineElement(Models.InlineElementType.CommitSHA, start, len, sha));
486486
}
487487

488+
var inlineCodeMatches = REG_INLINECODE_FORMAT().Matches(message);
489+
foreach (Match match in inlineCodeMatches)
490+
{
491+
var start = match.Index;
492+
var len = match.Length;
493+
if (inlines.Intersect(start, len) != null)
494+
continue;
495+
496+
inlines.Add(new Models.InlineElement(Models.InlineElementType.Code, start + 1, len - 2, string.Empty));
497+
}
498+
488499
inlines.Sort();
489500
return inlines;
490501
}
@@ -633,6 +644,9 @@ private async Task SetViewingCommitAsync(Models.Object file)
633644
[GeneratedRegex(@"\b([0-9a-fA-F]{6,40})\b")]
634645
private static partial Regex REG_SHA_FORMAT();
635646

647+
[GeneratedRegex(@"`.*?`")]
648+
private static partial Regex REG_INLINECODE_FORMAT();
649+
636650
private Repository _repo = null;
637651
private CommitDetailSharedData _sharedData = null;
638652
private Models.Commit _commit = null;

src/Views/CommitMessagePresenter.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
5454
if (link.Start > pos)
5555
inlines.Add(new Run(message.Substring(pos, link.Start - pos)));
5656

57+
var cls = link.Type switch
58+
{
59+
Models.InlineElementType.Link => "issue_link",
60+
Models.InlineElementType.CommitSHA => "commit_link",
61+
Models.InlineElementType.Code => "inline_code",
62+
_ => "normal"
63+
};
64+
5765
var run = new Run(message.Substring(link.Start, link.Length));
58-
run.Classes.Add(link.Type == Models.InlineElementType.CommitSHA ? "commit_link" : "issue_link");
66+
run.Classes.Add(cls);
5967
inlines.Add(run);
6068

6169
pos = link.Start + link.Length;
@@ -273,7 +281,7 @@ private void ProcessHoverCommitLink(Models.InlineElement link)
273281

274282
private void SetHoveredIssueLink(Models.InlineElement link)
275283
{
276-
if (link == _lastHover)
284+
if (link == _lastHover || link.Type == Models.InlineElementType.Code)
277285
return;
278286

279287
SetCurrentValue(CursorProperty, Cursor.Parse("Hand"));

0 commit comments

Comments
 (0)