feature: use Ctrl+C to copy selected commits in histories (#321)

This commit is contained in:
leo 2024-08-06 10:04:08 +08:00
parent b059423391
commit 4ba7c879c5
No known key found for this signature in database
2 changed files with 23 additions and 2 deletions

View file

@ -27,10 +27,12 @@
ColumnHeaderHeight="24" ColumnHeaderHeight="24"
HorizontalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
ClipboardCopyMode="None"
LayoutUpdated="OnCommitDataGridLayoutUpdated" LayoutUpdated="OnCommitDataGridLayoutUpdated"
SelectionChanged="OnCommitDataGridSelectionChanged" SelectionChanged="OnCommitDataGridSelectionChanged"
ContextRequested="OnCommitDataGridContextRequested" ContextRequested="OnCommitDataGridContextRequested"
DoubleTapped="OnCommitDataGridDoubleTapped"> DoubleTapped="OnCommitDataGridDoubleTapped"
KeyDown="OnCommitDataGridKeyDown">
<DataGrid.Styles> <DataGrid.Styles>
<Style Selector="DataGridColumnHeader"> <Style Selector="DataGridColumnHeader">
<Setter Property="MinHeight" Value="24"/> <Setter Property="MinHeight" Value="24"/>

View file

@ -1,5 +1,5 @@
using System; using System;
using System.Text;
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Controls.Primitives; using Avalonia.Controls.Primitives;
@ -419,5 +419,24 @@ namespace SourceGit.Views
} }
e.Handled = true; e.Handled = true;
} }
private void OnCommitDataGridKeyDown(object sender, KeyEventArgs e)
{
if (sender is DataGrid grid &&
grid.SelectedItems is { Count: > 0 } selected &&
e.Key == Key.C &&
e.KeyModifiers.HasFlag(KeyModifiers.Control))
{
var builder = new StringBuilder();
foreach (var item in selected)
{
if (item is Models.Commit commit)
builder.AppendLine($"{commit.SHA.Substring(0, 10)} - {commit.Subject}");
}
App.CopyText(builder.ToString());
e.Handled = true;
}
}
} }
} }