mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07: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
|
@ -129,7 +129,7 @@ namespace SourceGit.Commands
|
||||||
_oldLine = int.Parse(match.Groups[1].Value);
|
_oldLine = int.Parse(match.Groups[1].Value);
|
||||||
_newLine = int.Parse(match.Groups[2].Value);
|
_newLine = int.Parse(match.Groups[2].Value);
|
||||||
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
|
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace SourceGit.Commands
|
||||||
{
|
{
|
||||||
outputHandler?.Invoke(e.Data);
|
outputHandler?.Invoke(e.Data);
|
||||||
builder.AppendLine(e.Data);
|
builder.AppendLine(e.Data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
@ -118,7 +118,7 @@ namespace SourceGit.ViewModels
|
||||||
var trimmedUrl = url;
|
var trimmedUrl = url;
|
||||||
if (url.EndsWith(".git"))
|
if (url.EndsWith(".git"))
|
||||||
trimmedUrl = url.Substring(0, url.Length - 4);
|
trimmedUrl = url.Substring(0, url.Length - 4);
|
||||||
|
|
||||||
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
|
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
|
||||||
WebLinks.Add(new Models.CommitLink() { Name = $"Github ({trimmedUrl.Substring(19)})", URLPrefix = $"{url}/commit/" });
|
WebLinks.Add(new Models.CommitLink() { Name = $"Github ({trimmedUrl.Substring(19)})", URLPrefix = $"{url}/commit/" });
|
||||||
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))
|
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
Inlines.Add(new Run(subject));
|
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));
|
||||||
|
}
|
||||||
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)
|
||||||
inlines.Add(new Run(subject.Substring(pos, 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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
inlines.Add(new Run(subject.Substring(pos)));
|
{
|
||||||
|
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.AddRange(inlines);
|
Inlines.AddRange(inlines);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace SourceGit.Views
|
||||||
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
||||||
if (!startDirectly && OperatingSystem.IsMacOS())
|
if (!startDirectly && OperatingSystem.IsMacOS())
|
||||||
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
||||||
|
|
||||||
repo.Fetch(startDirectly);
|
repo.Fetch(startDirectly);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ namespace SourceGit.Views
|
||||||
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
||||||
if (!startDirectly && OperatingSystem.IsMacOS())
|
if (!startDirectly && OperatingSystem.IsMacOS())
|
||||||
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
||||||
|
|
||||||
repo.Pull(startDirectly);
|
repo.Pull(startDirectly);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ namespace SourceGit.Views
|
||||||
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
||||||
if (!startDirectly && OperatingSystem.IsMacOS())
|
if (!startDirectly && OperatingSystem.IsMacOS())
|
||||||
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
||||||
|
|
||||||
repo.Push(startDirectly);
|
repo.Push(startDirectly);
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue