refactor: use PointerPressed event instead of ListBox.SelectionChanged event to navigate to commit (#1230)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-23 10:17:14 +08:00
parent 345ad06aba
commit 7890f7abbf
No known key found for this signature in database
4 changed files with 133 additions and 101 deletions

View file

@ -318,6 +318,31 @@ namespace SourceGit.Views
}
}
private void OnNodePointerPressed(object sender, PointerPressedEventArgs e)
{
var p = e.GetCurrentPoint(this);
if (!p.Properties.IsLeftButtonPressed)
return;
if (DataContext is not ViewModels.Repository repo)
return;
if (sender is not Border { DataContext: ViewModels.BranchTreeNode node })
return;
if (node.Backend is not Models.Branch branch)
return;
if (BranchesPresenter.SelectedItems is { Count: > 0 })
{
var ctrl = OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control;
if (e.KeyModifiers.HasFlag(ctrl) || e.KeyModifiers.HasFlag(KeyModifiers.Shift))
return;
}
repo.NavigateToCommit(branch.Head);
}
private void OnNodesSelectionChanged(object _, SelectionChangedEventArgs e)
{
if (_disableSelectionChangingEvent)
@ -343,9 +368,6 @@ namespace SourceGit.Views
if (selected == null || selected.Count == 0)
return;
if (selected.Count == 1 && selected[0] is ViewModels.BranchTreeNode { Backend: Models.Branch branch })
repo.NavigateToCommit(branch.Head);
var prev = null as ViewModels.BranchTreeNode;
foreach (var row in Rows)
{