From 27a68f0d4d65cf21286faebd8a518e9ce12d99ac Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 26 Aug 2024 21:41:48 +0800 Subject: [PATCH] enhance: add inlines once time and mark text layout dirty (#400) --- src/Views/CommitMessagePresenter.cs | 12 ++++++++---- src/Views/Histories.axaml.cs | 10 ++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Views/CommitMessagePresenter.cs b/src/Views/CommitMessagePresenter.cs index bf19ecc7..031d6e77 100644 --- a/src/Views/CommitMessagePresenter.cs +++ b/src/Views/CommitMessagePresenter.cs @@ -89,21 +89,25 @@ namespace SourceGit.Views matches.Sort((l, r) => l.Start - r.Start); _matches = matches; - int pos = 0; + var inlines = new List(); + 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(); } } diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index a0828459..c2507721 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -212,22 +212,24 @@ namespace SourceGit.Views matches.Sort((l, r) => l.Start - r.Start); _matches = matches; - int pos = 0; + var inlines = new List(); + 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(); } }