Skip to content

Commit 7771c8c

Browse files
committed
feature: add hotkey to copy selected branch name (#2787)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 71a0b04 commit 7771c8c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎src/Views/BranchTree.axaml.cs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ private void OnTreeContextRequested(object _1, ContextRequestedEventArgs _2)
578578

579579
private void OnTreeKeyDown(object _, KeyEventArgs e)
580580
{
581-
if (e.Key == Key.F && e.KeyModifiers == (OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control))
581+
var cmdKey = OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control;
582+
if (e.Key == Key.F && e.KeyModifiers == cmdKey)
582583
{
583584
RaiseEvent(new RoutedEventArgs(SearchRequestedEvent));
584585
e.Handled = true;
@@ -635,6 +636,25 @@ private void OnTreeKeyDown(object _, KeyEventArgs e)
635636
e.Handled = true;
636637
}
637638
}
639+
else if (e.Key == Key.C && e.KeyModifiers == cmdKey)
640+
{
641+
var selected = BranchesPresenter.SelectedItems;
642+
if (selected == null)
643+
return;
644+
645+
var branches = new List<Models.Branch>();
646+
foreach (var item in selected)
647+
{
648+
if (item is ViewModels.BranchTreeNode node)
649+
CollectBranchesInNode(branches, node);
650+
}
651+
652+
if (branches.Count == 1)
653+
{
654+
var _1 = this.CopyTextAsync(branches[0].Name);
655+
e.Handled = true;
656+
}
657+
}
638658
}
639659

640660
private async void OnDoubleTappedBranchNode(object sender, TappedEventArgs _)
@@ -1086,6 +1106,7 @@ private ContextMenu CreateContextMenuForLocalBranch(ViewModels.Repository repo,
10861106
var copy = new MenuItem();
10871107
copy.Header = App.Text("BranchCM.CopyName");
10881108
copy.Icon = this.CreateMenuIcon("Icons.Copy");
1109+
copy.Tag = OperatingSystem.IsMacOS() ? "⌘+C" : "Ctrl+C";
10891110
copy.Click += async (_, e) =>
10901111
{
10911112
await this.CopyTextAsync(branch.Name);
@@ -1382,6 +1403,7 @@ public ContextMenu CreateContextMenuForRemoteBranch(ViewModels.Repository repo,
13821403
var copy = new MenuItem();
13831404
copy.Header = App.Text("BranchCM.CopyName");
13841405
copy.Icon = this.CreateMenuIcon("Icons.Copy");
1406+
copy.Tag = OperatingSystem.IsMacOS() ? "⌘+C" : "Ctrl+C";
13851407
copy.Click += async (_, e) =>
13861408
{
13871409
await this.CopyTextAsync(name);

0 commit comments

Comments
 (0)