From 0810e19f9330992c6fc87d7e36ed60ff99e6a216 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 12 May 2021 21:01:08 +0800 Subject: [PATCH] feature: enable Alt+MouseWheel for horizontal scrolling in DiffViewer --- src/Views/Widgets/DiffViewer.xaml.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Views/Widgets/DiffViewer.xaml.cs b/src/Views/Widgets/DiffViewer.xaml.cs index de9ce0cd..83e4f2c5 100644 --- a/src/Views/Widgets/DiffViewer.xaml.cs +++ b/src/Views/Widgets/DiffViewer.xaml.cs @@ -412,8 +412,9 @@ namespace SourceGit.Views.Widgets { grid.EnableColumnVirtualization = true; grid.RowHeight = 16.0; grid.FrozenColumnCount = lineNumbers.Length; - grid.ContextMenuOpening += OnTextDiffContextMenuOpening; grid.RowStyle = FindResource("Style.DataGridRow.DiffViewer") as Style; + grid.ContextMenuOpening += OnTextDiffContextMenuOpening; + grid.PreviewMouseWheel += OnTextDiffPreviewMouseWheel; grid.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, (o, e) => { var items = (o as DataGrid).SelectedItems; if (items.Count == 0) return; @@ -568,9 +569,23 @@ namespace SourceGit.Views.Widgets { e.Handled = true; } + private void OnTextDiffPreviewMouseWheel(object sender, MouseWheelEventArgs e) { + if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)) { + var editor = sender as DataGrid; + if (editor == null) return; + + var scroller = GetVisualChild(editor); + if (scroller == null || scroller.ComputedHorizontalScrollBarVisibility != Visibility.Visible) return; + + if (e.Delta > 0) scroller.LineLeft(); + else scroller.LineRight(); + + e.Handled = true; + } + } + private void OnTextDiffSyncScroll(object sender, ScrollChangedEventArgs e) { foreach (var editor in editors) { - var scroller = GetVisualChild(editor); if (scroller == null) continue;