mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-26 21:17:20 -08:00
enhance: supports issue link in keywords (#678)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
0842beb51d
commit
050b1d1188
5 changed files with 45 additions and 28 deletions
|
@ -192,35 +192,26 @@ namespace SourceGit.Views
|
||||||
if (string.IsNullOrEmpty(subject))
|
if (string.IsNullOrEmpty(subject))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var offset = 0;
|
|
||||||
var keywordMatch = REG_KEYWORD_FORMAT1().Match(subject);
|
var keywordMatch = REG_KEYWORD_FORMAT1().Match(subject);
|
||||||
if (!keywordMatch.Success)
|
if (!keywordMatch.Success)
|
||||||
keywordMatch = REG_KEYWORD_FORMAT2().Match(subject);
|
keywordMatch = REG_KEYWORD_FORMAT2().Match(subject);
|
||||||
|
|
||||||
if (keywordMatch.Success)
|
var rules = IssueTrackerRules ?? [];
|
||||||
{
|
|
||||||
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;
|
|
||||||
if (rules == null || rules.Count == 0)
|
|
||||||
{
|
|
||||||
Inlines.Add(new Run(subject));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var matches = new List<Models.Hyperlink>();
|
var matches = new List<Models.Hyperlink>();
|
||||||
foreach (var rule in rules)
|
foreach (var rule in rules)
|
||||||
rule.Matches(matches, subject);
|
rule.Matches(matches, subject);
|
||||||
|
|
||||||
if (matches.Count == 0)
|
if (matches.Count == 0)
|
||||||
|
{
|
||||||
|
if (keywordMatch.Success)
|
||||||
|
{
|
||||||
|
Inlines.Add(new Run(subject.Substring(0, keywordMatch.Length)) { FontWeight = FontWeight.Bold });
|
||||||
|
Inlines.Add(new Run(subject.Substring(keywordMatch.Length)));
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Inlines.Add(new Run(subject));
|
Inlines.Add(new Run(subject));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,18 +223,44 @@ namespace SourceGit.Views
|
||||||
foreach (var match in matches)
|
foreach (var match in matches)
|
||||||
{
|
{
|
||||||
if (match.Start > pos)
|
if (match.Start > pos)
|
||||||
|
{
|
||||||
|
if (keywordMatch.Success && pos < keywordMatch.Length)
|
||||||
|
{
|
||||||
|
if (keywordMatch.Length < match.Start)
|
||||||
|
{
|
||||||
|
inlines.Add(new Run(subject.Substring(pos, keywordMatch.Length - pos)) { FontWeight = FontWeight.Bold });
|
||||||
|
inlines.Add(new Run(subject.Substring(keywordMatch.Length, match.Start - keywordMatch.Length)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
inlines.Add(new Run(subject.Substring(pos, match.Start - pos)) { FontWeight = FontWeight.Bold });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
inlines.Add(new Run(subject.Substring(pos, match.Start - pos)));
|
inlines.Add(new Run(subject.Substring(pos, match.Start - pos)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var link = new Run(subject.Substring(match.Start, match.Length));
|
var link = new Run(subject.Substring(match.Start, match.Length));
|
||||||
link.Classes.Add("issue_link");
|
link.Classes.Add("issue_link");
|
||||||
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)
|
||||||
|
{
|
||||||
|
if (keywordMatch.Success && pos < keywordMatch.Length)
|
||||||
|
{
|
||||||
|
inlines.Add(new Run(subject.Substring(pos, keywordMatch.Length - pos)) { FontWeight = FontWeight.Bold });
|
||||||
|
inlines.Add(new Run(subject.Substring(keywordMatch.Length)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
inlines.Add(new Run(subject.Substring(pos)));
|
inlines.Add(new Run(subject.Substring(pos)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Inlines.AddRange(inlines);
|
Inlines.AddRange(inlines);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue