diff --git a/MultiTerm.Core/ViewModel/CommunicationDataViewModel.cs b/MultiTerm.Core/ViewModel/CommunicationDataViewModel.cs index c34c225..6bd850c 100644 --- a/MultiTerm.Core/ViewModel/CommunicationDataViewModel.cs +++ b/MultiTerm.Core/ViewModel/CommunicationDataViewModel.cs @@ -12,7 +12,6 @@ namespace MultiTerm.Core.ViewModel; public partial class CommunicationDataViewModel : ObservableObject, ICommunicationDataViewModel { private readonly IContext uiContext; - private int dataCharacterCount = 0; private List? listOfPreviousCharacters = null; @@ -32,6 +31,10 @@ public partial class CommunicationDataViewModel : ObservableObject, ICommunicati #endregion + /// + /// Newline Sequence string inserted on every newline in the . + /// + public static string NewlineSequence = Environment.NewLine; public CommunicationDataViewModel(IContext context) { @@ -134,7 +137,7 @@ public partial class CommunicationDataViewModel : ObservableObject, ICommunicati // increase line count lineCounter++; // append line in string - stringBuilder.AppendLine(); + stringBuilder.Append(NewlineSequence); break; case ShouldIntroduceNewlineAfterThisByteResult.RequiresMoreCharacters: @@ -198,7 +201,7 @@ public partial class CommunicationDataViewModel : ObservableObject, ICommunicati // increase line count collectionLineCounter++; // append line in string - stringBuilder.AppendLine(); + stringBuilder.Append(NewlineSequence); break; case ShouldIntroduceNewlineAfterThisByteResult.RequiresMoreCharacters: diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs b/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs index eb9d807..e82a44d 100644 --- a/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs +++ b/MultiTerm.Wpf.CustomControl/MultiFormatDataView/MultiFormatDataView.cs @@ -277,15 +277,22 @@ public class MultiFormatDataView : Control int selectionStartIndex = this.tbCharOnlyView!.SelectionStart; // TEMP OLD // extract text from the beginning to the start of the selected text - // var textFromBeginningToStartOfSelection = this.tbCharOnlyView!.Text.Substring(0, selectionStartIndex); + var textFromBeginningToStartOfSelection = this.tbCharOnlyView!.Text.Substring(0, selectionStartIndex); // count amount of manually introduced newline sequences in this text section (these to not exist in the data source!) - var foundManuallyIntroducedNewlineSequences = 0; // = textFromBeginningToStartOfSelection.Count((x) => x == DataViewModelToStringConverter.NewlineSequence); + var foundManuallyIntroducedNewlineSequenceCharacters = 0; + var foundAmountOfLines = textFromBeginningToStartOfSelection.Split(CommunicationDataViewModel.NewlineSequence).Length; + // any newline sequences introduced (more than one lines found) + if (foundAmountOfLines > 1) + { + // calculated amount of characters that were introduced + foundManuallyIntroducedNewlineSequenceCharacters = (foundAmountOfLines - 1) * CommunicationDataViewModel.NewlineSequence.Length; + } // iterate through length of selection for (int i = 0; i < this.tbCharOnlyView!.SelectionLength; i++) { // subtracting the counted newline sequences and adding i (length) - int elementPositionInCollection = selectionStartIndex - foundManuallyIntroducedNewlineSequences + i; + int elementPositionInCollection = selectionStartIndex - foundManuallyIntroducedNewlineSequenceCharacters + i; // add element to new selection list newSelection.Add(this.DataSource.Data.ElementAt(elementPositionInCollection)); // next item does not exist => break loop diff --git a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs index e8880ac..8c97f12 100644 --- a/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs +++ b/MultiTerm.Wpf.CustomControl/MultiFormatTextBox/MultiFormatTextBox.cs @@ -43,12 +43,24 @@ public class MultiFormatTextBox : Control #endregion + #region Dependency Properties public static readonly DependencyProperty CurrentMultiFormatStringProperty = DependencyProperty.Register("CurrentMultiFormatString", typeof(MultiFormatString), typeof(MultiFormatTextBox), new PropertyMetadata(null, OnCurrentMultiFormatStringChanged)); + public static readonly RoutedEvent EnterPressedEvent; + + /// + /// .NET Property for + /// + public event RoutedEventHandler EnterPressed + { + add { this.AddHandler(EnterPressedEvent, value); } + remove { this.RemoveHandler(EnterPressedEvent, value); } + } + /// /// .NET Property for CurrentMultiFormatString. /// @@ -63,6 +75,11 @@ public class MultiFormatTextBox : Control static MultiFormatTextBox() { DefaultStyleKeyProperty.OverrideMetadata(typeof(MultiFormatTextBox), new FrameworkPropertyMetadata(typeof(MultiFormatTextBox))); + + EnterPressedEvent = EventManager.RegisterRoutedEvent("EnterPressed", + RoutingStrategy.Bubble, typeof(RoutedEventArgs), + typeof(MultiFormatTextBox)); + } public override void OnApplyTemplate() @@ -264,8 +281,10 @@ public class MultiFormatTextBox : Control { if (e.Key == Key.Enter) { - // TODO Raise EnterPressedEvent Here e.Handled = true; + // raise event + RoutedEventArgs args = new(EnterPressedEvent); + RaiseEvent(args); } else if(e.Key == Key.Space) { diff --git a/MultiTerm.Wpf/View/SendReceiveView.xaml b/MultiTerm.Wpf/View/SendReceiveView.xaml index e305e21..02e0ed9 100644 --- a/MultiTerm.Wpf/View/SendReceiveView.xaml +++ b/MultiTerm.Wpf/View/SendReceiveView.xaml @@ -70,7 +70,15 @@