mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-26 20:00:59 +08:00
refactor: collecting inlines for subjects (#1402)
Instead of checking intersections of inline elements yourself before adding an inline element, the new class `InlineElementCollector` prevents intersections internally. Additionally the inline elements are sorted by the new class, so it's no longer necessary to do this after adding the inline elements.
This commit is contained in:
@@ -620,9 +620,9 @@ namespace SourceGit.ViewModels
|
||||
});
|
||||
}
|
||||
|
||||
private List<Models.InlineElement> ParseInlinesInMessage(string message)
|
||||
private Models.InlineElementCollector ParseInlinesInMessage(string message)
|
||||
{
|
||||
var inlines = new List<Models.InlineElement>();
|
||||
var inlines = new Models.InlineElementCollector();
|
||||
if (_repo.Settings.IssueTrackerRules is { Count: > 0 } rules)
|
||||
{
|
||||
foreach (var rule in rules)
|
||||
@@ -638,18 +638,6 @@ namespace SourceGit.ViewModels
|
||||
|
||||
var start = match.Index;
|
||||
var len = match.Length;
|
||||
var intersect = false;
|
||||
foreach (var link in inlines)
|
||||
{
|
||||
if (link.Intersect(start, len))
|
||||
{
|
||||
intersect = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersect)
|
||||
continue;
|
||||
|
||||
var url = message.Substring(start, len);
|
||||
if (Uri.IsWellFormedUriString(url, UriKind.Absolute))
|
||||
@@ -665,18 +653,6 @@ namespace SourceGit.ViewModels
|
||||
|
||||
var start = match.Index;
|
||||
var len = match.Length;
|
||||
var intersect = false;
|
||||
foreach (var link in inlines)
|
||||
{
|
||||
if (link.Intersect(start, len))
|
||||
{
|
||||
intersect = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (intersect)
|
||||
continue;
|
||||
|
||||
var sha = match.Groups[1].Value;
|
||||
var isCommitSHA = new Commands.IsCommitSHA(_repo.FullPath, sha).Result();
|
||||
@@ -684,9 +660,6 @@ namespace SourceGit.ViewModels
|
||||
inlines.Add(new Models.InlineElement(Models.InlineElementType.CommitSHA, start, len, sha));
|
||||
}
|
||||
|
||||
if (inlines.Count > 0)
|
||||
inlines.Sort((l, r) => l.Start - r.Start);
|
||||
|
||||
return inlines;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user