Skip to content

Commit 050b1d1

Browse files
committed
enhance: supports issue link in keywords (#678)
Signed-off-by: leo <[email protected]>
1 parent 0842beb commit 050b1d1

File tree

5 files changed

+45
-28
lines changed

5 files changed

+45
-28
lines changed

src/Commands/Diff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected override void OnReadline(string line)
129129
_oldLine = int.Parse(match.Groups[1].Value);
130130
_newLine = int.Parse(match.Groups[2].Value);
131131
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
132-
}
132+
}
133133
}
134134
else
135135
{

src/Commands/ExecuteCustomAction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void Run(string repo, string file, string args, Action<string> out
4444
{
4545
outputHandler?.Invoke(e.Data);
4646
builder.AppendLine(e.Data);
47-
}
47+
}
4848
};
4949

5050
try

src/ViewModels/CommitDetail.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public CommitDetail(Repository repo)
118118
var trimmedUrl = url;
119119
if (url.EndsWith(".git"))
120120
trimmedUrl = url.Substring(0, url.Length - 4);
121-
121+
122122
if (url.StartsWith("https://github.com/", StringComparison.Ordinal))
123123
WebLinks.Add(new Models.CommitLink() { Name = $"Github ({trimmedUrl.Substring(19)})", URLPrefix = $"{url}/commit/" });
124124
else if (url.StartsWith("https://gitlab.", StringComparison.Ordinal))

src/Views/Histories.axaml.cs

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,35 +192,26 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
192192
if (string.IsNullOrEmpty(subject))
193193
return;
194194

195-
var offset = 0;
196195
var keywordMatch = REG_KEYWORD_FORMAT1().Match(subject);
197196
if (!keywordMatch.Success)
198197
keywordMatch = REG_KEYWORD_FORMAT2().Match(subject);
199198

200-
if (keywordMatch.Success)
201-
{
202-
var keyword = new Run(subject.Substring(0, keywordMatch.Length));
203-
keyword.FontWeight = FontWeight.Bold;
204-
Inlines.Add(keyword);
205-
206-
offset = keywordMatch.Length;
207-
subject = subject.Substring(offset);
208-
}
209-
210-
var rules = IssueTrackerRules;
211-
if (rules == null || rules.Count == 0)
212-
{
213-
Inlines.Add(new Run(subject));
214-
return;
215-
}
216-
199+
var rules = IssueTrackerRules ?? [];
217200
var matches = new List<Models.Hyperlink>();
218201
foreach (var rule in rules)
219202
rule.Matches(matches, subject);
220203

221204
if (matches.Count == 0)
222205
{
223-
Inlines.Add(new Run(subject));
206+
if (keywordMatch.Success)
207+
{
208+
Inlines.Add(new Run(subject.Substring(0, keywordMatch.Length)) { FontWeight = FontWeight.Bold });
209+
Inlines.Add(new Run(subject.Substring(keywordMatch.Length)));
210+
}
211+
else
212+
{
213+
Inlines.Add(new Run(subject));
214+
}
224215
return;
225216
}
226217

@@ -232,18 +223,44 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
232223
foreach (var match in matches)
233224
{
234225
if (match.Start > pos)
235-
inlines.Add(new Run(subject.Substring(pos, match.Start - pos)));
226+
{
227+
if (keywordMatch.Success && pos < keywordMatch.Length)
228+
{
229+
if (keywordMatch.Length < match.Start)
230+
{
231+
inlines.Add(new Run(subject.Substring(pos, keywordMatch.Length - pos)) { FontWeight = FontWeight.Bold });
232+
inlines.Add(new Run(subject.Substring(keywordMatch.Length, match.Start - keywordMatch.Length)));
233+
}
234+
else
235+
{
236+
inlines.Add(new Run(subject.Substring(pos, match.Start - pos)) { FontWeight = FontWeight.Bold });
237+
}
238+
}
239+
else
240+
{
241+
inlines.Add(new Run(subject.Substring(pos, match.Start - pos)));
242+
}
243+
}
236244

237245
var link = new Run(subject.Substring(match.Start, match.Length));
238246
link.Classes.Add("issue_link");
239247
inlines.Add(link);
240248

241249
pos = match.Start + match.Length;
242-
match.Start += offset; // Because we use this index of whole subject to detect mouse event.
243250
}
244251

245252
if (pos < subject.Length)
246-
inlines.Add(new Run(subject.Substring(pos)));
253+
{
254+
if (keywordMatch.Success && pos < keywordMatch.Length)
255+
{
256+
inlines.Add(new Run(subject.Substring(pos, keywordMatch.Length - pos)) { FontWeight = FontWeight.Bold });
257+
inlines.Add(new Run(subject.Substring(keywordMatch.Length)));
258+
}
259+
else
260+
{
261+
inlines.Add(new Run(subject.Substring(pos)));
262+
}
263+
}
247264

248265
Inlines.AddRange(inlines);
249266
}

src/Views/RepositoryToolbar.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private void Fetch(object _, RoutedEventArgs e)
5252
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
5353
if (!startDirectly && OperatingSystem.IsMacOS())
5454
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
55-
55+
5656
repo.Fetch(startDirectly);
5757
e.Handled = true;
5858
}
@@ -66,7 +66,7 @@ private void Pull(object _, RoutedEventArgs e)
6666
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
6767
if (!startDirectly && OperatingSystem.IsMacOS())
6868
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
69-
69+
7070
repo.Pull(startDirectly);
7171
e.Handled = true;
7272
}
@@ -80,7 +80,7 @@ private void Push(object _, RoutedEventArgs e)
8080
var startDirectly = launcher.HasKeyModifier(KeyModifiers.Control);
8181
if (!startDirectly && OperatingSystem.IsMacOS())
8282
startDirectly = launcher.HasKeyModifier(KeyModifiers.Meta);
83-
83+
8484
repo.Push(startDirectly);
8585
e.Handled = true;
8686
}

0 commit comments

Comments
 (0)