Skip to content

Commit 88fd8f3

Browse files
authored
feature: double tap specific branch (#1416)
* feature: double tap specific branch * exactly match behavior of left sidebar
1 parent cadcf40 commit 88fd8f3

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src/ViewModels/Histories.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,47 @@ public void Select(IList commits)
209209
}
210210
}
211211

212-
public void DoubleTapped(Models.Commit commit)
212+
public void DoubleTapped(Models.Commit commit, Models.Decorator decorator = null)
213213
{
214+
if (decorator != null)
215+
{
216+
if (decorator.Type == Models.DecoratorType.LocalBranchHead)
217+
{
218+
var b = _repo.Branches.Find(x => x.FriendlyName == decorator.Name);
219+
if (b != null)
220+
{
221+
_repo.CheckoutBranch(b);
222+
return;
223+
}
224+
}
225+
else if (decorator.Type == Models.DecoratorType.RemoteBranchHead)
226+
{
227+
var remoteBranch = _repo.Branches.Find(x => x.FriendlyName == decorator.Name);
228+
if (remoteBranch != null)
229+
{
230+
var localBranch = _repo.Branches.Find(x => x.IsLocal && x.Upstream == remoteBranch.FullName);
231+
if (localBranch != null)
232+
{
233+
if (localBranch.IsCurrent)
234+
return;
235+
if (localBranch.TrackStatus.Ahead.Count > 0)
236+
{
237+
if (_repo.CanCreatePopup())
238+
_repo.ShowPopup(new CreateBranch(_repo, remoteBranch));
239+
}
240+
else if (localBranch.TrackStatus.Behind.Count > 0)
241+
{
242+
if (_repo.CanCreatePopup())
243+
_repo.ShowPopup(new CheckoutAndFastForward(_repo, localBranch, remoteBranch));
244+
}
245+
else
246+
_repo.CheckoutBranch(localBranch);
247+
return;
248+
}
249+
}
250+
}
251+
}
252+
214253
if (commit == null || commit.IsCurrentHead)
215254
return;
216255

src/Views/CommitRefsPresenter.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,22 @@ protected override void OnDataContextChanged(EventArgs e)
156156
InvalidateMeasure();
157157
}
158158

159+
public Models.Decorator DecoratorAt(Point point)
160+
{
161+
if (DataContext is not Models.Commit commit)
162+
return null;
163+
164+
var x = 0.0;
165+
for (var i = 0; i < _items.Count; i++)
166+
{
167+
x += _items[i].Width + 4;
168+
if (point.X < x)
169+
return commit.Decorators[i];
170+
}
171+
172+
return null;
173+
}
174+
159175
protected override Size MeasureOverride(Size availableSize)
160176
{
161177
_items.Clear();

src/Views/Histories.axaml.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,14 @@ private void OnCommitListDoubleTapped(object sender, TappedEventArgs e)
173173
{
174174
if (DataContext is ViewModels.Histories histories && sender is ListBox { SelectedItems.Count: 1 })
175175
{
176+
Models.Decorator decorator = null;
177+
if (e.Source is CommitRefsPresenter crp)
178+
decorator = crp.DecoratorAt(e.GetPosition(crp));
179+
176180
var source = e.Source as Control;
177181
var item = source.FindAncestorOfType<ListBoxItem>();
178182
if (item is { DataContext: Models.Commit commit })
179-
histories.DoubleTapped(commit);
183+
histories.DoubleTapped(commit, decorator);
180184
}
181185
e.Handled = true;
182186
}

0 commit comments

Comments
 (0)