diff --git a/SourceGit/UI/Blame.xaml b/SourceGit/UI/Blame.xaml
index a10fb900..02ec7a98 100644
--- a/SourceGit/UI/Blame.xaml
+++ b/SourceGit/UI/Blame.xaml
@@ -147,6 +147,7 @@
ScrollViewer.ScrollChanged="SyncScrollChanged"
PreviewMouseWheel="MouseWheelOnContent"
SizeChanged="ContentSizeChanged"
+ SelectionChanged="ContentSelectionChanged"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
FontFamily="Consolas">
diff --git a/SourceGit/UI/Blame.xaml.cs b/SourceGit/UI/Blame.xaml.cs
index 8d3f8b55..abf44055 100644
--- a/SourceGit/UI/Blame.xaml.cs
+++ b/SourceGit/UI/Blame.xaml.cs
@@ -210,5 +210,31 @@ namespace SourceGit.UI {
content.Document.PageWidth = content.ActualWidth;
}
}
+
+ ///
+ /// Auto scroll when selection changed.
+ ///
+ ///
+ ///
+ private void ContentSelectionChanged(object sender, RoutedEventArgs e) {
+ var doc = sender as RichTextBox;
+ if (doc == null || doc.IsFocused == false) return;
+
+ if (Mouse.LeftButton == MouseButtonState.Pressed && !doc.Selection.IsEmpty) {
+ var p = Mouse.GetPosition(doc);
+
+ if (p.X <= 8) {
+ doc.LineLeft();
+ } else if (p.X >= doc.ActualWidth - 8) {
+ doc.LineRight();
+ }
+
+ if (p.Y <= 8) {
+ doc.LineUp();
+ } else if (p.Y >= doc.ActualHeight - 8) {
+ doc.LineDown();
+ }
+ }
+ }
}
}
diff --git a/SourceGit/UI/DiffViewer.xaml b/SourceGit/UI/DiffViewer.xaml
index 2757981d..36ad0cc0 100644
--- a/SourceGit/UI/DiffViewer.xaml
+++ b/SourceGit/UI/DiffViewer.xaml
@@ -48,7 +48,7 @@
BorderThickness="0"
Background="Transparent"
IsReadOnly="True"
- Margin="4,0,4,0"
+ Margin="4,0,4,0"
FontSize="13"
HorizontalContentAlignment="Right"
VerticalAlignment="Stretch"/>
@@ -72,6 +72,7 @@
ScrollViewer.ScrollChanged="OnViewerScroll"
PreviewMouseWheel="OnViewerMouseWheel"
SizeChanged="LeftSizeChanged"
+ SelectionChanged="OnViewerSelectionChanged"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
@@ -126,6 +127,7 @@
ScrollViewer.ScrollChanged="OnViewerScroll"
PreviewMouseWheel="OnViewerMouseWheel"
SizeChanged="RightSizeChanged"
+ SelectionChanged="OnViewerSelectionChanged"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
diff --git a/SourceGit/UI/DiffViewer.xaml.cs b/SourceGit/UI/DiffViewer.xaml.cs
index a63ab5f8..38015266 100644
--- a/SourceGit/UI/DiffViewer.xaml.cs
+++ b/SourceGit/UI/DiffViewer.xaml.cs
@@ -268,17 +268,53 @@ namespace SourceGit.UI {
e.Handled = true;
}
+ ///
+ /// Fix document size for left side.
+ ///
+ ///
+ ///
private void LeftSizeChanged(object sender, SizeChangedEventArgs e) {
if (leftText.Document.PageWidth < leftText.ActualWidth) {
leftText.Document.PageWidth = leftText.ActualWidth;
}
}
+ ///
+ /// Fix document size for right side.
+ ///
+ ///
+ ///
private void RightSizeChanged(object sender, SizeChangedEventArgs e) {
if (rightText.Document.PageWidth < rightText.ActualWidth) {
rightText.Document.PageWidth = rightText.ActualWidth;
}
}
+
+ ///
+ /// Auto scroll when selection changed.
+ ///
+ ///
+ ///
+ private void OnViewerSelectionChanged(object sender, RoutedEventArgs e) {
+ var doc = sender as RichTextBox;
+ if (doc == null || doc.IsFocused == false) return;
+
+ if (Mouse.LeftButton == MouseButtonState.Pressed && !doc.Selection.IsEmpty) {
+ var p = Mouse.GetPosition(doc);
+
+ if (p.X <= 8) {
+ doc.LineLeft();
+ } else if (p.X >= doc.ActualWidth - 8) {
+ doc.LineRight();
+ }
+
+ if (p.Y <= 8) {
+ doc.LineUp();
+ } else if (p.Y >= doc.ActualHeight - 8) {
+ doc.LineDown();
+ }
+ }
+ }
#endregion
}
}