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

@ -1,5 +1,5 @@
using System;
using System.Text;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
@ -419,5 +419,24 @@ namespace SourceGit.Views
}
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;
}
}
}
}