From 3a662c0f40b7a6539ca2e54c4ba52d92b18af247 Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Fri, 13 Jun 2025 10:28:28 +1000 Subject: [PATCH 1/2] feature: double tap specific branch --- src/ViewModels/Histories.cs | 41 +++++++++++++++++++++++++++++++- src/Views/CommitRefsPresenter.cs | 16 +++++++++++++ src/Views/Histories.axaml.cs | 6 ++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index db368d806..04c762340 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -214,8 +214,47 @@ public void Select(IList commits) } } - public void DoubleTapped(Models.Commit commit) + public void DoubleTapped(Models.Commit commit, Models.Decorator decorator = null) { + if (decorator != null) + { + if (decorator.Type == Models.DecoratorType.LocalBranchHead) + { + var b = _repo.Branches.Find(x => x.FriendlyName == decorator.Name); + if (b != null) + { + _repo.CheckoutBranch(b); + return; + } + } + else if (decorator.Type == Models.DecoratorType.RemoteBranchHead) + { + var remoteBranch = _repo.Branches.Find(x => x.FriendlyName == decorator.Name); + if (remoteBranch != null) + { + var localBranch = _repo.Branches.Find(x => x.IsLocal && x.Upstream == remoteBranch.FullName); + if (localBranch != null) + { + if (localBranch.IsCurrent) + return; + if (localBranch.TrackStatus.Behind.Count == 0) + _repo.CheckoutBranch(localBranch); + else if (localBranch.TrackStatus.Ahead.Count == 0) + { + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CheckoutAndFastForward(_repo, localBranch, remoteBranch)); + } + else + { + if (_repo.CanCreatePopup()) + _repo.ShowPopup(new CreateBranch(_repo, remoteBranch)); + } + return; + } + } + } + } + if (commit == null || commit.IsCurrentHead) return; diff --git a/src/Views/CommitRefsPresenter.cs b/src/Views/CommitRefsPresenter.cs index 507da1c28..e8fa45178 100644 --- a/src/Views/CommitRefsPresenter.cs +++ b/src/Views/CommitRefsPresenter.cs @@ -156,6 +156,22 @@ protected override void OnDataContextChanged(EventArgs e) InvalidateMeasure(); } + public Models.Decorator DecoratorAt(Point point) + { + if (DataContext is not Models.Commit commit) + return null; + + var x = 0.0; + for (var i = 0; i < _items.Count; i++) + { + x += _items[i].Width + 4; + if (point.X < x) + return commit.Decorators[i]; + } + + return null; + } + protected override Size MeasureOverride(Size availableSize) { _items.Clear(); diff --git a/src/Views/Histories.axaml.cs b/src/Views/Histories.axaml.cs index 18630e4c2..995e8c1a7 100644 --- a/src/Views/Histories.axaml.cs +++ b/src/Views/Histories.axaml.cs @@ -182,10 +182,14 @@ private void OnCommitListDoubleTapped(object sender, TappedEventArgs e) { if (DataContext is ViewModels.Histories histories && sender is ListBox { SelectedItems.Count: 1 }) { + Models.Decorator decorator = null; + if (e.Source is CommitRefsPresenter crp) + decorator = crp.DecoratorAt(e.GetPosition(crp)); + var source = e.Source as Control; var item = source.FindAncestorOfType(); if (item is { DataContext: Models.Commit commit }) - histories.DoubleTapped(commit); + histories.DoubleTapped(commit, decorator); } e.Handled = true; } From 1c9a81274540afc0c304a5c44bf793024bc50e1c Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Fri, 13 Jun 2025 21:12:34 +1000 Subject: [PATCH 2/2] exactly match behavior of left sidebar --- src/ViewModels/Histories.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 04c762340..687035217 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -237,18 +237,18 @@ public void DoubleTapped(Models.Commit commit, Models.Decorator decorator = null { if (localBranch.IsCurrent) return; - if (localBranch.TrackStatus.Behind.Count == 0) - _repo.CheckoutBranch(localBranch); - else if (localBranch.TrackStatus.Ahead.Count == 0) + if (localBranch.TrackStatus.Ahead.Count > 0) { if (_repo.CanCreatePopup()) - _repo.ShowPopup(new CheckoutAndFastForward(_repo, localBranch, remoteBranch)); + _repo.ShowPopup(new CreateBranch(_repo, remoteBranch)); } - else + else if (localBranch.TrackStatus.Behind.Count > 0) { if (_repo.CanCreatePopup()) - _repo.ShowPopup(new CreateBranch(_repo, remoteBranch)); + _repo.ShowPopup(new CheckoutAndFastForward(_repo, localBranch, remoteBranch)); } + else + _repo.CheckoutBranch(localBranch); return; } }