enhance: add inlines once time and mark text layout dirty (#400)

This commit is contained in:
leo 2024-08-26 21:41:48 +08:00
parent 916d376c93
commit 27a68f0d4d
No known key found for this signature in database
2 changed files with 14 additions and 8 deletions

View file

@ -89,21 +89,25 @@ namespace SourceGit.Views
matches.Sort((l, r) => l.Start - r.Start);
_matches = matches;
int pos = 0;
var inlines = new List<Run>();
var pos = 0;
foreach (var match in matches)
{
if (match.Start > pos)
Inlines.Add(new Run(message.Substring(pos, match.Start - pos)));
inlines.Add(new Run(message.Substring(pos, match.Start - pos)));
var link = new Run(message.Substring(match.Start, match.Length));
link.Classes.Add(match.IsCommitSHA ? "commit_link" : "issue_link");
Inlines.Add(link);
inlines.Add(link);
pos = match.Start + match.Length;
}
if (pos < message.Length)
Inlines.Add(new Run(message.Substring(pos)));
inlines.Add(new Run(message.Substring(pos)));
Inlines.AddRange(inlines);
InvalidateTextLayout();
}
}

View file

@ -212,22 +212,24 @@ namespace SourceGit.Views
matches.Sort((l, r) => l.Start - r.Start);
_matches = matches;
int pos = 0;
var inlines = new List<Run>();
var pos = 0;
foreach (var match in matches)
{
if (match.Start > pos)
Inlines.Add(new Run(subject.Substring(pos, match.Start - pos)));
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);
inlines.Add(link);
pos = match.Start + match.Length;
}
if (pos < subject.Length)
Inlines.Add(new Run(subject.Substring(pos)));
inlines.Add(new Run(subject.Substring(pos)));
Inlines.AddRange(inlines);
InvalidateTextLayout();
}
}