Skip to content

Commit d74afec

Browse files
committed
refactor: use IndexOf instead of regex exp to test keyword in subject
Signed-off-by: leo <longshuang@msn.cn>
1 parent a165fd2 commit d74afec

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/Views/CommitSubjectPresenter.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ private void GenerateInlineElements()
248248
foreach (var rule in rules)
249249
rule.Matches(_elements, subject);
250250

251-
var keywordMatch = REG_KEYWORD_FORMAT().Match(subject);
252-
if (keywordMatch.Success)
251+
if (subject.StartsWith('['))
253252
{
254-
if (_elements.Intersect(0, keywordMatch.Length) == null)
255-
_elements.Add(new Models.InlineElement(Models.InlineElementType.Keyword, 0, keywordMatch.Length, string.Empty));
253+
var bracketIdx = subject.IndexOf(']');
254+
if (bracketIdx > 1 && bracketIdx < 50 && _elements.Intersect(0, bracketIdx + 1) == null)
255+
_elements.Add(new Models.InlineElement(Models.InlineElementType.Keyword, 0, bracketIdx + 1, string.Empty));
256256
}
257257
else
258258
{
@@ -386,9 +386,6 @@ private void ClearHoveredIssueLink()
386386
[GeneratedRegex(@"`.*?`")]
387387
private static partial Regex REG_INLINECODE_FORMAT();
388388

389-
[GeneratedRegex(@"^\[[^]]{1,48}?\]")]
390-
private static partial Regex REG_KEYWORD_FORMAT();
391-
392389
private class Inline
393390
{
394391
public double X { get; set; } = 0;
@@ -404,8 +401,8 @@ public Inline(double x, FormattedText text, Models.InlineElement elem)
404401
}
405402

406403
private Models.InlineElementCollector _elements = new();
407-
private List<Inline> _inlines = [];
408404
private Models.InlineElement _lastHover = null;
405+
private List<Inline> _inlines = [];
409406
private bool _needRebuildInlines = false;
410407
}
411408
}

0 commit comments

Comments
 (0)