Skip to content

Commit a4306fe

Browse files
committed
feature: double-clicking tag will try to checkout (detached mode) the revision refered by selected tag (#1661)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 406db5a commit a4306fe

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/ViewModels/Repository.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,13 @@ public void CheckoutBranch(Models.Branch branch)
14481448
}
14491449
}
14501450

1451+
public async Task CheckoutTagAsync(Models.Tag tag)
1452+
{
1453+
var c = await new Commands.QuerySingleCommit(_fullpath, tag.SHA).GetResultAsync();
1454+
if (c != null)
1455+
_histories?.CheckoutBranchByCommit(c);
1456+
}
1457+
14511458
public async Task CompareBranchWithWorktree(Models.Branch branch)
14521459
{
14531460
if (_histories != null)

src/Views/TagsView.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<Border Height="24"
9797
Background="Transparent"
9898
PointerPressed="OnItemPointerPressed"
99+
DoubleTapped="OnItemDoubleTapped"
99100
ContextRequested="OnItemContextRequested"
100101
ToolTip.Placement="Right">
101102
<ToolTip.Tip>

src/Views/TagsView.axaml.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,20 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
155155
}
156156
}
157157

158-
private void OnItemDoubleTapped(object sender, TappedEventArgs e)
158+
private async void OnItemDoubleTapped(object sender, TappedEventArgs e)
159159
{
160-
if (sender is Control { DataContext: ViewModels.TagTreeNode { IsFolder: true } node })
161-
ToggleNodeIsExpanded(node);
160+
if (sender is Control { DataContext: ViewModels.TagTreeNode node })
161+
{
162+
if (node.IsFolder)
163+
ToggleNodeIsExpanded(node);
164+
else if (DataContext is ViewModels.Repository repo)
165+
await repo.CheckoutTagAsync(node.Tag);
166+
}
167+
else if (sender is Control { DataContext: Models.Tag tag })
168+
{
169+
if (DataContext is ViewModels.Repository repo)
170+
await repo.CheckoutTagAsync(tag);
171+
}
162172

163173
e.Handled = true;
164174
}

0 commit comments

Comments
 (0)