From f3a2c98f18751db35997a6341ffc24ce54d1851b Mon Sep 17 00:00:00 2001 From: Jonas Arnold Date: Tue, 6 Jun 2023 20:03:42 +0200 Subject: [PATCH] implemented automatic focus of the send messagebox after inserting a history element in both ConsoleView and SendReceiveView, simplifies instant send after inserting --- .../MultiFormatTextBox/MultiFormatTextBox.cs | 2 ++ MultiTerm.Wpf/View/ConsoleView.xaml | 3 ++- MultiTerm.Wpf/View/ConsoleView.xaml.cs | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs index 8718910..85d2f2e 100644 --- a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs +++ b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs @@ -170,6 +170,8 @@ public class MultiFormatTextBox : Control mftb.AddItemsToTextBox(mftb.CurrentMultiFormatString, 0); } + // focus richtextbox on change of content (e.g. due to insertion of history element) + mftb.richTextBox!.Focus(); } /// diff --git a/MultiTerm.Wpf/View/ConsoleView.xaml b/MultiTerm.Wpf/View/ConsoleView.xaml index c485f75..46ae11e 100644 --- a/MultiTerm.Wpf/View/ConsoleView.xaml +++ b/MultiTerm.Wpf/View/ConsoleView.xaml @@ -115,6 +115,7 @@ AllowDrop="False" Text="{Binding Path=SendableMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource DataContainerFontStyle}" - PreviewKeyDown="SendableMessageTextBox_PreviewKeyDown"/> + PreviewKeyDown="SendableMessageTextBox_PreviewKeyDown" + TextChanged="SendableMessageTextBox_TextChanged"/> diff --git a/MultiTerm.Wpf/View/ConsoleView.xaml.cs b/MultiTerm.Wpf/View/ConsoleView.xaml.cs index 1143a47..9145956 100644 --- a/MultiTerm.Wpf/View/ConsoleView.xaml.cs +++ b/MultiTerm.Wpf/View/ConsoleView.xaml.cs @@ -1,5 +1,6 @@ using MultiTerm.Core.ViewModel; using System; +using System.Linq; using System.Windows.Controls; using System.Windows.Input; @@ -61,4 +62,17 @@ public partial class ConsoleView : UserControl if (sender is not TextBox textBox) { return; } textBox.ScrollToEnd(); } + + private void SendableMessageTextBox_TextChanged(object sender, TextChangedEventArgs e) + { + // more than one change and added length is more than 1 letter + // => suspect change results from inserting an element from the send history or pasted from the clipboard + if (e.Changes.Count >= 1 && e.Changes.First().AddedLength > 1) + { + // focus the textbox + this.sendableMessageTextBox.Focus(); + // set cursor to end + this.sendableMessageTextBox.CaretIndex = this.sendableMessageTextBox.Text.Length; + } + } } \ No newline at end of file