diff --git a/src/UI/CommitViewer.xaml.cs b/src/UI/CommitViewer.xaml.cs index 7659a303..95411d0a 100644 --- a/src/UI/CommitViewer.xaml.cs +++ b/src/UI/CommitViewer.xaml.cs @@ -446,6 +446,21 @@ namespace SourceGit.UI { grid.FrozenColumnCount = 1; grid.ContextMenuOpening += OnPreviewContextMenuOpening; grid.RowStyle = FindResource("Style.DataGridRow.NoBringIntoView") as Style; + grid.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (o, e) => { + var items = (o as DataGrid).SelectedItems; + if (items.Count == 0) return; + + var builder = new StringBuilder(); + foreach (var item in items) { + var line = item as Git.Commit.Line; + if (line == null) continue; + + builder.Append(line.Content); + builder.AppendLine(); + } + + Clipboard.SetText(builder.ToString()); + })); var colLineNumber = new DataGridTextColumn(); colLineNumber.IsReadOnly = true; diff --git a/src/UI/DiffViewer.xaml.cs b/src/UI/DiffViewer.xaml.cs index 30eaec63..2267f9b7 100644 --- a/src/UI/DiffViewer.xaml.cs +++ b/src/UI/DiffViewer.xaml.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; +using System.Windows.Input; using System.Windows.Media; using System.Windows.Shapes; using System.Windows.Threading; @@ -425,6 +426,22 @@ namespace SourceGit.UI { grid.FrozenColumnCount = lineNumbers.Length; grid.ContextMenuOpening += OnTextChangeContextMenuOpening; grid.RowStyle = FindResource("Style.DataGridRow.NoBringIntoView") as Style; + grid.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (o, e) => { + var items = (o as DataGrid).SelectedItems; + if (items.Count == 0) return; + + var builder = new StringBuilder(); + foreach (var item in items) { + var block = item as ChangeBlock; + if (block == null) continue; + if (!block.IsContent) continue; + + builder.Append(block.Content); + builder.AppendLine(); + } + + Clipboard.SetText(builder.ToString()); + })); foreach (var number in lineNumbers) { var colLineNumber = new DataGridTextColumn();