feature<TextEdit>: supports scroll by mouse wheel

This commit is contained in:
leo 2023-11-07 09:33:49 +08:00
parent 8fa3a558a0
commit b0d5c1fd52
4 changed files with 47 additions and 2 deletions

View file

@ -35,6 +35,24 @@ namespace SourceGit.Views.Controls {
SelectionChanged += OnSelectionChanged;
}
protected override void OnMouseWheel(MouseWheelEventArgs e) {
base.OnMouseWheel(e);
if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) {
if (e.Delta > 0) {
LineLeft();
} else {
LineRight();
}
} else {
if (e.Delta > 0) {
LineUp();
} else {
LineDown();
}
}
}
private void OnTextChanged(object sender, TextChangedEventArgs e) {
PlaceholderVisibility = string.IsNullOrEmpty(Text) ? Visibility.Visible : Visibility.Collapsed;
}

View file

@ -170,7 +170,7 @@
BorderThickness="0"
TextWrapping="Wrap"
Margin="11,5,16,0"
MaxHeight="80"
MaxHeight="100"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
VerticalAlignment="Top"/>

View file

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
namespace SourceGit.Views.Widgets {
@ -44,6 +45,7 @@ namespace SourceGit.Views.Widgets {
private void UpdateInformation(Models.Commit commit) {
txtSHA.Text = commit.SHA;
txtMessage.Text = (commit.Subject + "\n\n" + commit.Message.Trim()).Trim();
txtMessage.ScrollToHome();
avatarAuthor.Email = commit.Author.Email;
avatarAuthor.FallbackLabel = commit.Author.Name;
@ -90,6 +92,10 @@ namespace SourceGit.Views.Widgets {
Dispatcher.Invoke(() => {
changeList.ItemsSource = changes;
ScrollViewer sw = GetVisualChild<ScrollViewer>(changeList);
if (sw != null) sw.ScrollToHome();
changeContainer.SetData(repo, new List<Models.Commit>() { commit }, changes);
});
});
@ -189,5 +195,25 @@ namespace SourceGit.Views.Widgets {
e.Handled = true;
}
#endregion
private T GetVisualChild<T>(DependencyObject parent) where T : Visual {
T child = null;
int count = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < count; i++) {
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null) {
child = GetVisualChild<T>(v);
}
if (child != null) {
break;
}
}
return child;
}
}
}

View file

@ -53,10 +53,11 @@
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Border
Grid.Column="0" Grid.ColumnSpan="2"
Grid.Column="0" Grid.ColumnSpan="3"
Background="{DynamicResource Brush.Contents}"
BorderThickness="1" BorderBrush="{DynamicResource Brush.Border0}"
CornerRadius="14"/>