mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-16 16:05:00 +00: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:
parent
ba4c0f0cd2
commit
fe54d30b70
6 changed files with 109 additions and 79 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue