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:
Sina Hinderks 2025-06-08 02:47:03 +02:00 committed by GitHub
parent ba4c0f0cd2
commit fe54d30b70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 109 additions and 79 deletions

View file

@ -167,19 +167,6 @@ namespace SourceGit.Views
var start = match.Index;
var len = match.Length;
var intersect = false;
foreach (var exist in _elements)
{
if (exist.Intersect(start, len))
{
intersect = true;
break;
}
}
if (intersect)
continue;
_elements.Add(new Models.InlineElement(Models.InlineElementType.Code, start, len, string.Empty));
}
@ -187,7 +174,6 @@ namespace SourceGit.Views
foreach (var rule in rules)
rule.Matches(_elements, subject);
_elements.Sort((l, r) => l.Start - r.Start);
_needRebuildInlines = true;
InvalidateVisual();
}
@ -364,7 +350,7 @@ namespace SourceGit.Views
}
}
private List<Models.InlineElement> _elements = [];
private Models.InlineElementCollector _elements = [];
private List<Inline> _inlines = [];
private Models.InlineElement _lastHover = null;
private bool _needRebuildInlines = false;