private void InputRichTextBox_OnSelectionChanged(object sender, RoutedEventArgs e) { if (MirrorToggleButton.IsChecked == false) { return; } OutputRichTextBox.ClearFormatting(); if (InputRichTextBox.Selection.IsEmpty || OutputRichTextBox.IsEmpty() || _containKeys) { return; } var inputStartPointer = InputRichTextBox.GetStart(); var outputStartPointer = OutputRichTextBox.GetStart(); var selectionStartPointer = InputRichTextBox.Selection.Start; var selectedText = InputRichTextBox.Selection.Text; var precedingText = new TextRange(inputStartPointer, selectionStartPointer).Text; var encodedSelectedText = _selectedCipher.Encode(selectedText, CharsDelimiter, WordsDelimiter); var encodedPrecedingText = _selectedCipher.Encode(precedingText, CharsDelimiter, WordsDelimiter); var highlightStartPointer = outputStartPointer.GetPositionAtOffset(encodedPrecedingText.Length + 2); var highlightEndPointer = highlightStartPointer?.GetPositionAtOffset(encodedSelectedText.Length + 2); var highlightTextRange = new TextRange(highlightStartPointer, highlightEndPointer); var brush = _isLight ? Brushes.Yellow : Brushes.DarkMagenta; highlightTextRange.ApplyPropertyValue(TextElement.BackgroundProperty, brush); }
//// Footer Event Handlers //// private void ToggleThemeButton_Click(object sender, RoutedEventArgs e) { var mode = _isLight ? BaseTheme.Dark : BaseTheme.Light; ThemeAssist.SetTheme(this, mode); _isLight ^= true; OutputRichTextBox.ClearFormatting(); }
private void MirrorSelectionToggleButton_Unchecked(object sender, RoutedEventArgs e) { OutputRichTextBox.ClearFormatting(); }