mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2025-01-10 23:47:21 -08:00
feature: use bold font for keyword
prefix of commit subject
Regexes to detect `keyword` * ^(\[[\w\s]+\]) * ^(\w+\s?:)
This commit is contained in:
parent
7f8a1c384a
commit
8f9e2cefe9
1 changed files with 24 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Collections;
|
using Avalonia.Collections;
|
||||||
|
@ -155,7 +156,7 @@ namespace SourceGit.Views
|
||||||
private Status _status = Status.Normal;
|
private Status _status = Status.Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CommitSubjectPresenter : TextBlock
|
public partial class CommitSubjectPresenter : TextBlock
|
||||||
{
|
{
|
||||||
public static readonly StyledProperty<string> SubjectProperty =
|
public static readonly StyledProperty<string> SubjectProperty =
|
||||||
AvaloniaProperty.Register<CommitSubjectPresenter, string>(nameof(Subject));
|
AvaloniaProperty.Register<CommitSubjectPresenter, string>(nameof(Subject));
|
||||||
|
@ -191,6 +192,21 @@ namespace SourceGit.Views
|
||||||
if (string.IsNullOrEmpty(subject))
|
if (string.IsNullOrEmpty(subject))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var offset = 0;
|
||||||
|
var keywordMatch = REG_KEYWORD_FORMAT1().Match(subject);
|
||||||
|
if (!keywordMatch.Success)
|
||||||
|
keywordMatch = REG_KEYWORD_FORMAT2().Match(subject);
|
||||||
|
|
||||||
|
if (keywordMatch.Success)
|
||||||
|
{
|
||||||
|
var keyword = new Run(subject.Substring(0, keywordMatch.Length));
|
||||||
|
keyword.FontWeight = FontWeight.Bold;
|
||||||
|
Inlines.Add(keyword);
|
||||||
|
|
||||||
|
offset = keywordMatch.Length;
|
||||||
|
subject = subject.Substring(offset);
|
||||||
|
}
|
||||||
|
|
||||||
var rules = IssueTrackerRules;
|
var rules = IssueTrackerRules;
|
||||||
if (rules == null || rules.Count == 0)
|
if (rules == null || rules.Count == 0)
|
||||||
{
|
{
|
||||||
|
@ -223,6 +239,7 @@ namespace SourceGit.Views
|
||||||
inlines.Add(link);
|
inlines.Add(link);
|
||||||
|
|
||||||
pos = match.Start + match.Length;
|
pos = match.Start + match.Length;
|
||||||
|
match.Start += offset; // Because we use this index of whole subject to detect mouse event.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos < subject.Length)
|
if (pos < subject.Length)
|
||||||
|
@ -288,6 +305,12 @@ namespace SourceGit.Views
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^(\[[\w\s]+\])")]
|
||||||
|
private static partial Regex REG_KEYWORD_FORMAT1();
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^(\w+\s?:)")]
|
||||||
|
private static partial Regex REG_KEYWORD_FORMAT2();
|
||||||
|
|
||||||
private List<Models.Hyperlink> _matches = null;
|
private List<Models.Hyperlink> _matches = null;
|
||||||
private Models.Hyperlink _lastHover = null;
|
private Models.Hyperlink _lastHover = null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue