mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-10-31 13:03:20 -07:00
Enable auto scroll when selection changed in RichTextBox
This commit is contained in:
parent
4680608845
commit
ab9b89b4cc
4 changed files with 66 additions and 1 deletions
|
@ -147,6 +147,7 @@
|
||||||
ScrollViewer.ScrollChanged="SyncScrollChanged"
|
ScrollViewer.ScrollChanged="SyncScrollChanged"
|
||||||
PreviewMouseWheel="MouseWheelOnContent"
|
PreviewMouseWheel="MouseWheelOnContent"
|
||||||
SizeChanged="ContentSizeChanged"
|
SizeChanged="ContentSizeChanged"
|
||||||
|
SelectionChanged="ContentSelectionChanged"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
FontFamily="Consolas">
|
FontFamily="Consolas">
|
||||||
|
|
|
@ -210,5 +210,31 @@ namespace SourceGit.UI {
|
||||||
content.Document.PageWidth = content.ActualWidth;
|
content.Document.PageWidth = content.ActualWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Auto scroll when selection changed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
BorderThickness="0"
|
BorderThickness="0"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Margin="4,0,4,0"
|
Margin="4,0,4,0"
|
||||||
FontSize="13"
|
FontSize="13"
|
||||||
HorizontalContentAlignment="Right"
|
HorizontalContentAlignment="Right"
|
||||||
VerticalAlignment="Stretch"/>
|
VerticalAlignment="Stretch"/>
|
||||||
|
@ -72,6 +72,7 @@
|
||||||
ScrollViewer.ScrollChanged="OnViewerScroll"
|
ScrollViewer.ScrollChanged="OnViewerScroll"
|
||||||
PreviewMouseWheel="OnViewerMouseWheel"
|
PreviewMouseWheel="OnViewerMouseWheel"
|
||||||
SizeChanged="LeftSizeChanged"
|
SizeChanged="LeftSizeChanged"
|
||||||
|
SelectionChanged="OnViewerSelectionChanged"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Stretch">
|
VerticalAlignment="Stretch">
|
||||||
<RichTextBox.Document>
|
<RichTextBox.Document>
|
||||||
|
@ -126,6 +127,7 @@
|
||||||
ScrollViewer.ScrollChanged="OnViewerScroll"
|
ScrollViewer.ScrollChanged="OnViewerScroll"
|
||||||
PreviewMouseWheel="OnViewerMouseWheel"
|
PreviewMouseWheel="OnViewerMouseWheel"
|
||||||
SizeChanged="RightSizeChanged"
|
SizeChanged="RightSizeChanged"
|
||||||
|
SelectionChanged="OnViewerSelectionChanged"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
VerticalAlignment="Stretch">
|
VerticalAlignment="Stretch">
|
||||||
<RichTextBox.Document>
|
<RichTextBox.Document>
|
||||||
|
|
|
@ -268,17 +268,53 @@ namespace SourceGit.UI {
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fix document size for left side.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void LeftSizeChanged(object sender, SizeChangedEventArgs e) {
|
private void LeftSizeChanged(object sender, SizeChangedEventArgs e) {
|
||||||
if (leftText.Document.PageWidth < leftText.ActualWidth) {
|
if (leftText.Document.PageWidth < leftText.ActualWidth) {
|
||||||
leftText.Document.PageWidth = leftText.ActualWidth;
|
leftText.Document.PageWidth = leftText.ActualWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fix document size for right side.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void RightSizeChanged(object sender, SizeChangedEventArgs e) {
|
private void RightSizeChanged(object sender, SizeChangedEventArgs e) {
|
||||||
if (rightText.Document.PageWidth < rightText.ActualWidth) {
|
if (rightText.Document.PageWidth < rightText.ActualWidth) {
|
||||||
rightText.Document.PageWidth = rightText.ActualWidth;
|
rightText.Document.PageWidth = rightText.ActualWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Auto scroll when selection changed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue