implemented automatic focus of the send messagebox after inserting a history element in both ConsoleView and SendReceiveView,

simplifies instant send after inserting
master
Jonas Arnold 3 years ago
parent 9aeff6dfec
commit f3a2c98f18
  1. 2
      MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs
  2. 3
      MultiTerm.Wpf/View/ConsoleView.xaml
  3. 14
      MultiTerm.Wpf/View/ConsoleView.xaml.cs

@ -170,6 +170,8 @@ public class MultiFormatTextBox : Control
mftb.AddItemsToTextBox(mftb.CurrentMultiFormatString, 0); mftb.AddItemsToTextBox(mftb.CurrentMultiFormatString, 0);
} }
// focus richtextbox on change of content (e.g. due to insertion of history element)
mftb.richTextBox!.Focus();
} }
/// <summary> /// <summary>

@ -115,6 +115,7 @@
AllowDrop="False" AllowDrop="False"
Text="{Binding Path=SendableMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Text="{Binding Path=SendableMessage, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource DataContainerFontStyle}" Style="{StaticResource DataContainerFontStyle}"
PreviewKeyDown="SendableMessageTextBox_PreviewKeyDown"/> PreviewKeyDown="SendableMessageTextBox_PreviewKeyDown"
TextChanged="SendableMessageTextBox_TextChanged"/>
</Grid> </Grid>
</UserControl> </UserControl>

@ -1,5 +1,6 @@
using MultiTerm.Core.ViewModel; using MultiTerm.Core.ViewModel;
using System; using System;
using System.Linq;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@ -61,4 +62,17 @@ public partial class ConsoleView : UserControl
if (sender is not TextBox textBox) { return; } if (sender is not TextBox textBox) { return; }
textBox.ScrollToEnd(); 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;
}
}
} }
Loading…
Cancel
Save