refactor: commit message

- move issue tracker and commit hash links parsing to view models
- parsing links async
- make sure matched hash is a valid commit oid
- disable `CHILDREN` row in submodule info panel

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-03-04 16:04:19 +08:00
parent 5301a368e0
commit b75676a7f8
No known key found for this signature in database
17 changed files with 191 additions and 186 deletions

View file

@ -0,0 +1,17 @@
namespace SourceGit.Commands
{
public class IsCommitSHA : Command
{
public IsCommitSHA(string repo, string hash)
{
WorkingDirectory = repo;
Args = $"cat-file -t {hash}";
}
public bool Result()
{
var rs = ReadToEnd();
return rs.IsSuccess && rs.StdOut.Trim().Equals("commit");
}
}
}

View file

@ -3,18 +3,18 @@ using System.Collections.Generic;
namespace SourceGit.Commands
{
public class QueryCommitsWithFullMessage : Command
public class QueryCommitsForInteractiveRebase : Command
{
public QueryCommitsWithFullMessage(string repo, string args)
public QueryCommitsForInteractiveRebase(string repo, string on)
{
_boundary = $"----- BOUNDARY OF COMMIT {Guid.NewGuid()} -----";
WorkingDirectory = repo;
Context = repo;
Args = $"log --date-order --no-show-signature --decorate=full --pretty=format:\"%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%B%n{_boundary}\" {args}";
Args = $"log --date-order --no-show-signature --decorate=full --pretty=format:\"%H%n%P%n%D%n%aN±%aE%n%at%n%cN±%cE%n%ct%n%B%n{_boundary}\" {on}..HEAD";
}
public List<Models.CommitWithMessage> Result()
public List<Models.InteractiveCommit> Result()
{
var rs = ReadToEnd();
if (!rs.IsSuccess)
@ -29,7 +29,7 @@ namespace SourceGit.Commands
switch (nextPartIdx)
{
case 0:
_current = new Models.CommitWithMessage();
_current = new Models.InteractiveCommit();
_current.Commit.SHA = line;
_commits.Add(_current);
break;
@ -52,7 +52,7 @@ namespace SourceGit.Commands
_current.Commit.CommitterTime = ulong.Parse(line);
break;
default:
var boundary = rs.StdOut.IndexOf(_boundary, end + 1);
var boundary = rs.StdOut.IndexOf(_boundary, end + 1, StringComparison.Ordinal);
if (boundary > end)
{
_current.Message = rs.StdOut.Substring(start, boundary - start - 1);
@ -88,8 +88,8 @@ namespace SourceGit.Commands
_current.Commit.Parents.AddRange(data.Split(separator: ' ', options: StringSplitOptions.RemoveEmptyEntries));
}
private List<Models.CommitWithMessage> _commits = new List<Models.CommitWithMessage>();
private Models.CommitWithMessage _current = null;
private List<Models.InteractiveCommit> _commits = [];
private Models.InteractiveCommit _current = null;
private string _boundary = "";
}
}

View file

@ -112,9 +112,9 @@ namespace SourceGit.Models
}
}
public class CommitWithMessage
public class CommitFullMessage
{
public Commit Commit { get; set; } = new Commit();
public string Message { get; set; } = "";
public string Message { get; set; } = string.Empty;
public List<Hyperlink> Links { get; set; } = [];
}
}

View file

@ -12,6 +12,12 @@ namespace SourceGit.Models
Drop,
}
public class InteractiveCommit
{
public Commit Commit { get; set; } = new Commit();
public string Message { get; set; } = string.Empty;
}
public class InteractiveRebaseJob
{
public string SHA { get; set; } = string.Empty;

View file

@ -29,6 +29,6 @@ namespace SourceGit.Models
public class RevisionSubmodule
{
public Commit Commit { get; set; } = null;
public string FullMessage { get; set; } = string.Empty;
public CommitFullMessage FullMessage { get; set; } = null;
}
}

View file

@ -5,7 +5,6 @@ using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using Avalonia.Platform.Storage;
@ -46,7 +45,7 @@ namespace SourceGit.ViewModels
}
}
public string FullMessage
public Models.CommitFullMessage FullMessage
{
get => _fullMessage;
private set => SetProperty(ref _fullMessage, value);
@ -85,11 +84,11 @@ namespace SourceGit.ViewModels
}
}
public AvaloniaList<string> Children
public List<string> Children
{
get;
private set;
} = [];
get => _children;
private set => SetProperty(ref _children, value);
}
public string SearchChangeFilter
{
@ -109,17 +108,12 @@ namespace SourceGit.ViewModels
set => SetProperty(ref _viewRevisionFileContent, value);
}
public AvaloniaList<Models.CommitLink> WebLinks
public List<Models.CommitLink> WebLinks
{
get;
private set;
} = [];
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
{
get => _repo.Settings?.IssueTrackerRules;
}
public string RevisionFileSearchFilter
{
get => _revisionFileSearchFilter;
@ -127,25 +121,23 @@ namespace SourceGit.ViewModels
{
if (SetProperty(ref _revisionFileSearchFilter, value))
{
RevisionFileSearchSuggestion.Clear();
if (!string.IsNullOrEmpty(value))
{
if (_revisionFiles.Count == 0)
if (_revisionFiles == null)
{
var sha = Commit.SHA;
Task.Run(() =>
{
var files = new Commands.QueryRevisionFileNames(_repo.FullPath, sha).Result();
var filesList = new List<string>();
filesList.AddRange(files);
Dispatcher.UIThread.Invoke(() =>
{
if (sha == Commit.SHA)
{
_revisionFiles.Clear();
_revisionFiles.AddRange(files);
_revisionFiles = filesList;
if (!string.IsNullOrEmpty(_revisionFileSearchFilter))
UpdateRevisionFileSearchSuggestion();
}
@ -159,23 +151,17 @@ namespace SourceGit.ViewModels
}
else
{
IsRevisionFileSearchSuggestionOpen = false;
RevisionFileSearchSuggestion = null;
GC.Collect();
}
}
}
}
public AvaloniaList<string> RevisionFileSearchSuggestion
public List<string> RevisionFileSearchSuggestion
{
get;
private set;
} = [];
public bool IsRevisionFileSearchSuggestionOpen
{
get => _isRevisionFileSearchSuggestionOpen;
set => SetProperty(ref _isRevisionFileSearchSuggestionOpen, value);
get => _revisionFileSearchSuggestion;
private set => SetProperty(ref _revisionFileSearchSuggestion, value);
}
public CommitDetail(Repository repo)
@ -212,23 +198,17 @@ namespace SourceGit.ViewModels
{
_repo = null;
_commit = null;
if (_changes != null)
_changes.Clear();
if (_visibleChanges != null)
_visibleChanges.Clear();
if (_selectedChanges != null)
_selectedChanges.Clear();
_changes = null;
_visibleChanges = null;
_selectedChanges = null;
_signInfo = null;
_searchChangeFilter = null;
_diffContext = null;
_viewRevisionFileContent = null;
_cancelToken = null;
WebLinks.Clear();
_revisionFiles.Clear();
RevisionFileSearchSuggestion.Clear();
_revisionFiles = null;
_revisionFileSearchSuggestion = null;
}
public void NavigateTo(string commitSHA)
@ -251,6 +231,11 @@ namespace SourceGit.ViewModels
RevisionFileSearchFilter = string.Empty;
}
public void CancelRevisionFileSuggestions()
{
RevisionFileSearchSuggestion = null;
}
public Models.Commit GetParent(string sha)
{
return new Commands.QuerySingleCommit(_repo.FullPath, sha).Result();
@ -322,7 +307,12 @@ namespace SourceGit.ViewModels
if (commit != null)
{
var body = new Commands.QueryCommitFullMessage(submoduleRoot, file.SHA).Result();
var submodule = new Models.RevisionSubmodule() { Commit = commit, FullMessage = body };
var submodule = new Models.RevisionSubmodule()
{
Commit = commit,
FullMessage = new Models.CommitFullMessage { Message = body }
};
Dispatcher.UIThread.Invoke(() => ViewRevisionFileContent = submodule);
}
else
@ -332,7 +322,7 @@ namespace SourceGit.ViewModels
ViewRevisionFileContent = new Models.RevisionSubmodule()
{
Commit = new Models.Commit() { SHA = file.SHA },
FullMessage = string.Empty,
FullMessage = null,
};
});
}
@ -622,23 +612,22 @@ namespace SourceGit.ViewModels
private void Refresh()
{
_changes = null;
_revisionFiles.Clear();
_revisionFiles = null;
SignInfo = null;
ViewRevisionFileContent = null;
Children.Clear();
Children = null;
RevisionFileSearchFilter = string.Empty;
IsRevisionFileSearchSuggestionOpen = false;
GC.Collect();
RevisionFileSearchSuggestion = null;
if (_commit == null)
return;
Task.Run(() =>
{
var fullMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA).Result();
Dispatcher.UIThread.Invoke(() => FullMessage = fullMessage);
var message = new Commands.QueryCommitFullMessage(_repo.FullPath, _commit.SHA).Result();
var links = ParseLinksInMessage(message);
Dispatcher.UIThread.Invoke(() => FullMessage = new Models.CommitFullMessage { Message = message, Links = links });
});
Task.Run(() =>
@ -694,6 +683,49 @@ namespace SourceGit.ViewModels
});
}
private List<Models.Hyperlink> ParseLinksInMessage(string message)
{
var links = new List<Models.Hyperlink>();
if (_repo.Settings.IssueTrackerRules is { Count: > 0 } rules)
{
foreach (var rule in rules)
rule.Matches(links, message);
}
var shas = REG_SHA_FORMAT().Matches(message);
for (int i = 0; i < shas.Count; i++)
{
var sha = shas[i];
if (!sha.Success)
continue;
var hash = sha.Groups[1].Value;
var test = new Commands.IsCommitSHA(_repo.FullPath, hash).Result();
if (!test)
continue;
var start = sha.Index;
var len = sha.Length;
var intersect = false;
foreach (var link in links)
{
if (link.Intersect(start, len))
{
intersect = true;
break;
}
}
if (!intersect)
links.Add(new Models.Hyperlink(start, len, hash, true));
}
if (links.Count > 0)
links.Sort((l, r) => l.Start - r.Start);
return links;
}
private void RefreshVisibleChanges()
{
if (_changes == null)
@ -813,11 +845,12 @@ namespace SourceGit.ViewModels
break;
}
RevisionFileSearchSuggestion.Clear();
RevisionFileSearchSuggestion.AddRange(suggestion);
IsRevisionFileSearchSuggestionOpen = suggestion.Count > 0;
RevisionFileSearchSuggestion = suggestion;
}
[GeneratedRegex(@"\b([0-9a-fA-F]{6,40})\b")]
private static partial Regex REG_SHA_FORMAT();
[GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]
private static partial Regex REG_LFS_FORMAT();
@ -828,8 +861,9 @@ namespace SourceGit.ViewModels
private Repository _repo = null;
private Models.Commit _commit = null;
private string _fullMessage = string.Empty;
private Models.CommitFullMessage _fullMessage = null;
private Models.CommitSignInfo _signInfo = null;
private List<string> _children = null;
private List<Models.Change> _changes = null;
private List<Models.Change> _visibleChanges = null;
private List<Models.Change> _selectedChanges = null;
@ -837,8 +871,8 @@ namespace SourceGit.ViewModels
private DiffContext _diffContext = null;
private object _viewRevisionFileContent = null;
private Commands.Command.CancelToken _cancelToken = null;
private List<string> _revisionFiles = [];
private List<string> _revisionFiles = null;
private string _revisionFileSearchFilter = string.Empty;
private bool _isRevisionFileSearchSuggestionOpen = false;
private List<string> _revisionFileSearchSuggestion = null;
}
}

View file

@ -235,13 +235,17 @@ namespace SourceGit.ViewModels
if (commit != null)
{
var body = new Commands.QueryCommitFullMessage(repo, sha).Result();
return new Models.RevisionSubmodule() { Commit = commit, FullMessage = body };
return new Models.RevisionSubmodule()
{
Commit = commit,
FullMessage = new Models.CommitFullMessage { Message = body }
};
}
return new Models.RevisionSubmodule()
{
Commit = new Models.Commit() { SHA = sha },
FullMessage = string.Empty,
FullMessage = null,
};
}

View file

@ -123,12 +123,20 @@ namespace SourceGit.ViewModels
if (commit != null)
{
var message = new Commands.QueryCommitFullMessage(submoduleRoot, obj.SHA).Result();
var module = new Models.RevisionSubmodule() { Commit = commit, FullMessage = message };
var module = new Models.RevisionSubmodule()
{
Commit = commit,
FullMessage = new Models.CommitFullMessage { Message = message }
};
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
}
else
{
var module = new Models.RevisionSubmodule() { Commit = new Models.Commit() { SHA = obj.SHA }, FullMessage = "" };
var module = new Models.RevisionSubmodule()
{
Commit = new Models.Commit() { SHA = obj.SHA },
FullMessage = null
};
Dispatcher.UIThread.Invoke(() => ViewContent = new FileHistoriesRevisionFile(_file, module));
}
});

View file

@ -118,7 +118,7 @@ namespace SourceGit.ViewModels
Task.Run(() =>
{
var commits = new Commands.QueryCommitsWithFullMessage(repoPath, $"{on.SHA}..HEAD").Result();
var commits = new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA).Result();
var list = new List<InteractiveRebaseItem>();
foreach (var c in commits)

View file

@ -95,8 +95,8 @@
</StackPanel>
<!-- PARENTS -->
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Parents}" IsVisible="{Binding Parents.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"/>
<ItemsControl Grid.Row="1" Grid.Column="1" Height="24" Margin="12,0,0,0" ItemsSource="{Binding Parents}" IsVisible="{Binding Parents.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
<TextBlock Grid.Row="1" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Parents}" IsVisible="{Binding Parents, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"/>
<ItemsControl Grid.Row="1" Grid.Column="1" Height="24" Margin="12,0,0,0" ItemsSource="{Binding Parents}" IsVisible="{Binding Parents, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"/>
@ -133,8 +133,8 @@
</ItemsControl>
<!-- CHILDREN -->
<TextBlock Grid.Row="2" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Children}" IsVisible="{Binding #ThisControl.Children.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}"/>
<ItemsControl Grid.Row="2" Grid.Column="1" Margin="12,0,0,0" ItemsSource="{Binding #ThisControl.Children}" IsVisible="{Binding #ThisControl.Children.Count, Converter={x:Static c:IntConverters.IsGreaterThanZero}}">
<TextBlock Grid.Row="2" Grid.Column="0" Classes="info_label" VerticalAlignment="Top" Margin="0,4,0,0" Text="{DynamicResource Text.CommitDetail.Info.Children}" IsVisible="{Binding #ThisControl.Children, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}"/>
<ItemsControl Grid.Row="2" Grid.Column="1" Margin="12,0,0,0" ItemsSource="{Binding #ThisControl.Children}" IsVisible="{Binding #ThisControl.Children, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" VerticalAlignment="Center" ItemHeight="24"/>
@ -187,8 +187,7 @@
<v:CommitMessagePresenter Grid.Row="4" Grid.Column="1"
Margin="12,4,8,0"
Classes="primary"
Message="{Binding #ThisControl.Message}"
IssueTrackerRules="{Binding #ThisControl.IssueTrackerRules}"
FullMessage="{Binding #ThisControl.FullMessage}"
HorizontalAlignment="Stretch"
TextWrapping="Wrap">
<v:CommitMessagePresenter.DataTemplates>

View file

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
@ -11,13 +11,13 @@ namespace SourceGit.Views
{
public partial class CommitBaseInfo : UserControl
{
public static readonly StyledProperty<string> MessageProperty =
AvaloniaProperty.Register<CommitBaseInfo, string>(nameof(Message), string.Empty);
public static readonly StyledProperty<Models.CommitFullMessage> FullMessageProperty =
AvaloniaProperty.Register<CommitBaseInfo, Models.CommitFullMessage>(nameof(FullMessage));
public string Message
public Models.CommitFullMessage FullMessage
{
get => GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
get => GetValue(FullMessageProperty);
set => SetValue(FullMessageProperty, value);
}
public static readonly StyledProperty<Models.CommitSignInfo> SignInfoProperty =
@ -38,28 +38,19 @@ namespace SourceGit.Views
set => SetValue(SupportsContainsInProperty, value);
}
public static readonly StyledProperty<AvaloniaList<Models.CommitLink>> WebLinksProperty =
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.CommitLink>>(nameof(WebLinks));
public static readonly StyledProperty<List<Models.CommitLink>> WebLinksProperty =
AvaloniaProperty.Register<CommitBaseInfo, List<Models.CommitLink>>(nameof(WebLinks));
public AvaloniaList<Models.CommitLink> WebLinks
public List<Models.CommitLink> WebLinks
{
get => GetValue(WebLinksProperty);
set => SetValue(WebLinksProperty, value);
}
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
public static readonly StyledProperty<List<string>> ChildrenProperty =
AvaloniaProperty.Register<CommitBaseInfo, List<string>>(nameof(Children));
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
{
get => GetValue(IssueTrackerRulesProperty);
set => SetValue(IssueTrackerRulesProperty, value);
}
public static readonly StyledProperty<AvaloniaList<string>> ChildrenProperty =
AvaloniaProperty.Register<CommitBaseInfo, AvaloniaList<string>>(nameof(Children));
public AvaloniaList<string> Children
public List<string> Children
{
get => GetValue(ChildrenProperty);
set => SetValue(ChildrenProperty, value);

View file

@ -20,12 +20,11 @@
<StackPanel Orientation="Vertical">
<!-- Base Information -->
<v:CommitBaseInfo Content="{Binding Commit}"
Message="{Binding FullMessage}"
FullMessage="{Binding FullMessage}"
SignInfo="{Binding SignInfo}"
SupportsContainsIn="True"
WebLinks="{Binding WebLinks}"
Children="{Binding Children}"
IssueTrackerRules="{Binding IssueTrackerRules}"/>
Children="{Binding Children}"/>
<!-- Line -->
<Rectangle Height=".65" Margin="8" Fill="{DynamicResource Brush.Border2}"/>

View file

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Documents;
using Avalonia.Input;
@ -13,27 +11,15 @@ using Avalonia.VisualTree;
namespace SourceGit.Views
{
public partial class CommitMessagePresenter : SelectableTextBlock
public class CommitMessagePresenter : SelectableTextBlock
{
[GeneratedRegex(@"\b([0-9a-fA-F]{6,40})\b")]
private static partial Regex REG_SHA_FORMAT();
public static readonly StyledProperty<Models.CommitFullMessage> FullMessageProperty =
AvaloniaProperty.Register<CommitMessagePresenter, Models.CommitFullMessage>(nameof(FullMessage));
public static readonly StyledProperty<string> MessageProperty =
AvaloniaProperty.Register<CommitMessagePresenter, string>(nameof(Message));
public string Message
public Models.CommitFullMessage FullMessage
{
get => GetValue(MessageProperty);
set => SetValue(MessageProperty, value);
}
public static readonly StyledProperty<AvaloniaList<Models.IssueTrackerRule>> IssueTrackerRulesProperty =
AvaloniaProperty.Register<CommitMessagePresenter, AvaloniaList<Models.IssueTrackerRule>>(nameof(IssueTrackerRules));
public AvaloniaList<Models.IssueTrackerRule> IssueTrackerRules
{
get => GetValue(IssueTrackerRulesProperty);
set => SetValue(IssueTrackerRulesProperty, value);
get => GetValue(FullMessageProperty);
set => SetValue(FullMessageProperty, value);
}
protected override Type StyleKeyOverride => typeof(SelectableTextBlock);
@ -42,69 +28,36 @@ namespace SourceGit.Views
{
base.OnPropertyChanged(change);
if (change.Property == MessageProperty || change.Property == IssueTrackerRulesProperty)
if (change.Property == FullMessageProperty)
{
Inlines!.Clear();
_inlineCommits.Clear();
_matches = null;
_lastHover = null;
ClearHoveredIssueLink();
var message = Message;
var message = FullMessage?.Message;
if (string.IsNullOrEmpty(message))
return;
var matches = new List<Models.Hyperlink>();
if (IssueTrackerRules is { Count: > 0 } rules)
{
foreach (var rule in rules)
rule.Matches(matches, message);
}
var shas = REG_SHA_FORMAT().Matches(message);
for (int i = 0; i < shas.Count; i++)
{
var sha = shas[i];
if (!sha.Success)
continue;
var start = sha.Index;
var len = sha.Length;
var intersect = false;
foreach (var match in matches)
{
if (match.Intersect(start, len))
{
intersect = true;
break;
}
}
if (!intersect)
matches.Add(new Models.Hyperlink(start, len, sha.Groups[1].Value, true));
}
if (matches.Count == 0)
var links = FullMessage?.Links;
if (links == null || links.Count == 0)
{
Inlines.Add(new Run(message));
return;
}
matches.Sort((l, r) => l.Start - r.Start);
_matches = matches;
var inlines = new List<Inline>();
var pos = 0;
foreach (var match in matches)
foreach (var link in links)
{
if (match.Start > pos)
inlines.Add(new Run(message.Substring(pos, match.Start - pos)));
if (link.Start > pos)
inlines.Add(new Run(message.Substring(pos, link.Start - pos)));
var link = new Run(message.Substring(match.Start, match.Length));
link.Classes.Add(match.IsCommitSHA ? "commit_link" : "issue_link");
inlines.Add(link);
var run = new Run(message.Substring(link.Start, link.Length));
run.Classes.Add(link.IsCommitSHA ? "commit_link" : "issue_link");
inlines.Add(run);
pos = match.Start + match.Length;
pos = link.Start + link.Length;
}
if (pos < message.Length)
@ -134,7 +87,7 @@ namespace SourceGit.Views
scrollViewer.LineDown();
}
}
else if (_matches != null)
else if (FullMessage is { Links: { Count: > 0 } links })
{
var point = e.GetPosition(this) - new Point(Padding.Left, Padding.Top);
var x = Math.Min(Math.Max(point.X, 0), Math.Max(TextLayout.WidthIncludingTrailingWhitespace, 0));
@ -142,25 +95,25 @@ namespace SourceGit.Views
point = new Point(x, y);
var pos = TextLayout.HitTestPoint(point).TextPosition;
foreach (var match in _matches)
foreach (var link in links)
{
if (!match.Intersect(pos, 1))
if (!link.Intersect(pos, 1))
continue;
if (match == _lastHover)
if (link == _lastHover)
return;
SetCurrentValue(CursorProperty, Cursor.Parse("Hand"));
_lastHover = match;
if (!match.IsCommitSHA)
_lastHover = link;
if (!link.IsCommitSHA)
{
ToolTip.SetTip(this, match.Link);
ToolTip.SetTip(this, link.Link);
ToolTip.SetIsOpen(this, true);
}
else
{
ProcessHoverCommitLink(match);
ProcessHoverCommitLink(link);
}
return;
@ -361,7 +314,6 @@ namespace SourceGit.Views
}
}
private List<Models.Hyperlink> _matches = null;
private Models.Hyperlink _lastHover = null;
private Dictionary<string, Models.Commit> _inlineCommits = new();
}

View file

@ -257,7 +257,7 @@
<ContentControl.DataTemplates>
<DataTemplate DataType="m:RevisionSubmodule">
<Border Margin="0,0,0,8" BorderThickness="1" BorderBrush="{DynamicResource Brush.Border1}" Background="{DynamicResource Brush.Window}">
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding Commit}" Message="{Binding FullMessage}"/>
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding Commit}" FullMessage="{Binding FullMessage}"/>
</Border>
</DataTemplate>
</ContentControl.DataTemplates>
@ -271,7 +271,7 @@
<Path Width="16" Height="16" Data="{StaticResource Icons.DoubleDown}" HorizontalAlignment="Center" IsVisible="{Binding Old, Converter={x:Static ObjectConverters.IsNotNull}}"/>
<Border Margin="0,8,0,0" BorderThickness="1" BorderBrush="Green" Background="{DynamicResource Brush.Window}">
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding New.Commit}" Message="{Binding New.FullMessage}"/>
<v:CommitBaseInfo MaxHeight="256" Margin="0,0,0,4" Content="{Binding New.Commit}" FullMessage="{Binding New.FullMessage}"/>
</Border>
</StackPanel>
</ScrollViewer>

View file

@ -63,7 +63,7 @@
<Grid RowDefinitions="Auto,*" Margin="8,0">
<TextBlock Grid.Row="0" Margin="0,8,0,0" Text="{DynamicResource Text.CommitDetail.Files.Submodule}" FontSize="18" FontWeight="Bold" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.FG2}"/>
<ScrollViewer Grid.Row="1" Margin="0,16,0,0" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<v:CommitBaseInfo Content="{Binding Commit}" Message="{Binding FullMessage}"/>
<v:CommitBaseInfo Content="{Binding Commit}" FullMessage="{Binding FullMessage}"/>
</ScrollViewer>
</Grid>
</DataTemplate>

View file

@ -44,7 +44,7 @@
<Popup PlacementTarget="{Binding #TxtSearchRevisionFiles}"
Placement="BottomEdgeAlignedLeft"
HorizontalOffset="-8" VerticalAlignment="-8"
IsOpen="{Binding IsRevisionFileSearchSuggestionOpen}">
IsOpen="{Binding RevisionFileSearchSuggestion, Converter={x:Static c:ListConverters.IsNotNullOrEmpty}}">
<Border Margin="8" VerticalAlignment="Top" Effect="drop-shadow(0 0 8 #80000000)">
<Border Background="{DynamicResource Brush.Popup}" CornerRadius="4" Padding="4" BorderThickness="0.65" BorderBrush="{DynamicResource Brush.Accent}">
<ListBox x:Name="SearchSuggestionBox"

View file

@ -23,7 +23,7 @@ namespace SourceGit.Views
}
else if (e.Key == Key.Down || e.Key == Key.Up)
{
if (vm.IsRevisionFileSearchSuggestionOpen)
if (vm.RevisionFileSearchSuggestion.Count > 0)
{
SearchSuggestionBox.Focus(NavigationMethod.Tab);
SearchSuggestionBox.SelectedIndex = 0;
@ -33,12 +33,7 @@ namespace SourceGit.Views
}
else if (e.Key == Key.Escape)
{
if (vm.IsRevisionFileSearchSuggestionOpen)
{
vm.RevisionFileSearchSuggestion.Clear();
vm.IsRevisionFileSearchSuggestionOpen = false;
}
vm.CancelRevisionFileSuggestions();
e.Handled = true;
}
}
@ -57,7 +52,7 @@ namespace SourceGit.Views
if (e.Key == Key.Escape)
{
vm.RevisionFileSearchSuggestion.Clear();
vm.CancelRevisionFileSuggestions();
e.Handled = true;
}
else if (e.Key == Key.Enter && SearchSuggestionBox.SelectedItem is string content)