Skip to content

Commit 0bf22f5

Browse files
committed
enhance: better keyword detection of commit subject
Signed-off-by: leo <longshuang@msn.cn>
1 parent f8c1a18 commit 0bf22f5

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/Views/CommitSubjectPresenter.cs

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

251-
var keywordMatch = REG_KEYWORD_FORMAT1().Match(subject);
252-
if (!keywordMatch.Success)
253-
keywordMatch = REG_KEYWORD_FORMAT2().Match(subject);
254-
255-
if (keywordMatch.Success && _elements.Intersect(0, keywordMatch.Length) == null)
256-
_elements.Add(new Models.InlineElement(Models.InlineElementType.Keyword, 0, keywordMatch.Length, string.Empty));
251+
var keywordMatch = REG_KEYWORD_FORMAT().Match(subject);
252+
if (keywordMatch.Success)
253+
{
254+
if (_elements.Intersect(0, keywordMatch.Length) == null)
255+
_elements.Add(new Models.InlineElement(Models.InlineElementType.Keyword, 0, keywordMatch.Length, string.Empty));
256+
}
257+
else
258+
{
259+
var colonIdx = subject.IndexOf(':', StringComparison.Ordinal);
260+
if (colonIdx > 0 && colonIdx < 32 && colonIdx < subject.Length - 2 && char.IsWhiteSpace(subject[colonIdx + 1]) && _elements.Intersect(0, colonIdx + 1) == null)
261+
_elements.Add(new Models.InlineElement(Models.InlineElementType.Keyword, 0, colonIdx + 1, string.Empty));
262+
}
257263

258264
var codeMatches = REG_INLINECODE_FORMAT().Matches(subject);
259265
foreach (Match match in codeMatches)
@@ -370,11 +376,8 @@ private void ClearHoveredIssueLink()
370376
[GeneratedRegex(@"`.*?`")]
371377
private static partial Regex REG_INLINECODE_FORMAT();
372378

373-
[GeneratedRegex(@"^\[[\w\s]+\]")]
374-
private static partial Regex REG_KEYWORD_FORMAT1();
375-
376-
[GeneratedRegex(@"^\S+([\<\(][\w\s_\-\*,]+[\>\)])?\!?\s?:\s")]
377-
private static partial Regex REG_KEYWORD_FORMAT2();
379+
[GeneratedRegex(@"^\[[^]]{1,48}?\]")]
380+
private static partial Regex REG_KEYWORD_FORMAT();
378381

379382
private class Inline
380383
{

0 commit comments

Comments
 (0)