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);
|
||||
_newLine = int.Parse(match.Groups[2].Value);
|
||||
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace SourceGit.Commands
|
|||
{
|
||||
outputHandler?.Invoke(e.Data);
|
||||
builder.AppendLine(e.Data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace SourceGit.ViewModels
|
|||
var trimmedUrl = url;
|
||||
if (url.EndsWith(".git"))
|
||||
trimmedUrl = url.Substring(0, url.Length - 4);
|
||||
|
||||
|
||||
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
|
||||
WebLinks.Add(new Models.CommitLink() { Name = $"Github ({trimmedUrl.Substring(19)})", URLPrefix = $"{url}/commit/" });
|
||||
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))
|
||||
|
|
|
@ -192,35 +192,26 @@ namespace SourceGit.Views
|
|||
if (string.IsNullOrEmpty(subject))
|
||||
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;
|
||||
if (rules == null || rules.Count == 0)
|
||||
{
|
||||
Inlines.Add(new Run(subject));
|
||||
return;
|
||||
}
|
||||
|
||||
var rules = IssueTrackerRules ?? [];
|
||||
var matches = new List<Models.Hyperlink>();
|
||||
foreach (var rule in rules)
|
||||
rule.Matches(matches, subject);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -232,18 +223,44 @@ namespace SourceGit.Views
|
|||
foreach (var match in matches)
|
||||
{
|
||||
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));
|
||||
link.Classes.Add("issue_link");
|
||||
inlines.Add(link);
|
||||
|
||||
pos = match.Start + match.Length;
|
||||
match.Start += offset; // Because we use this index of whole subject to detect mouse event.
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace SourceGit.Views
|
|||
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
||||
if (!startDirectly && OperatingSystem.IsMacOS())
|
||||
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
||||
|
||||
|
||||
repo.Fetch(startDirectly);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ namespace SourceGit.Views
|
|||
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
||||
if (!startDirectly && OperatingSystem.IsMacOS())
|
||||
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
||||
|
||||
|
||||
repo.Pull(startDirectly);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ namespace SourceGit.Views
|
|||
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
|
||||
if (!startDirectly && OperatingSystem.IsMacOS())
|
||||
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
|
||||
|
||||
|
||||
repo.Push(startDirectly);
|
||||
e.Handled = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue