internal static void SetTextUndoable(this TextBox textBox, string text)
 {
     // http://stackoverflow.com/questions/27083236/change-the-text-in-a-textbox-with-text-binding-sometext-so-it-is-undoable/27083548?noredirect=1#comment42677255_27083548
     // Dunno if nice, testing it for now
     textBox.BeginChange();
     textBox.Text = text;
     textBox.EndChange();
 }
 /// <summary>
 /// Insert the given text into this RichTextBox at the current CaretPosition, replacing any already-selected text.
 /// </summary>
 /// <param name="richTextBox">The RichTextBox to insert the new text into</param>
 /// <param name="sTextToInsert">The text to insert into this RichTextBox</param>
 public static void InsertText(this System.Windows.Controls.RichTextBox richTextBox, string sTextToInsert)
 {
     if (!String.IsNullOrEmpty(sTextToInsert))
     {
         //TODO
     #if !SILVERLIGHT
         richTextBox.BeginChange();
         if (richTextBox.Selection.Text != string.Empty)
         {
             richTextBox.Selection.Text = string.Empty;
         }
         TextPointer tp = richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward);
         richTextBox.CaretPosition.InsertTextInRun(sTextToInsert);
         richTextBox.CaretPosition = tp;
         richTextBox.EndChange();
         Keyboard.Focus(richTextBox);
     #endif
     }
 }
 public static void ReplaceAll(this TextEditor editor, Regex find, string replace)
 {
     try
     {
         var offset = 0;
         editor.BeginChange();
         foreach (Match match in find.Matches(editor.Text))
         {
             var replaceWith = match.Result(replace);
             editor.Document.Replace(offset + match.Index, match.Length, replaceWith);
             offset += replaceWith.Length - match.Length;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
     }
     finally
     {
         editor.EndChange();
     }
 }