I want to move the caret 4 positions to the right of where my caret currently is. I'm registered for PreviewKeyDown, and calling InsertTextInRun() when the tab key is captured, like so:
private void rtb_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Tab)
{
rtb.CaretPosition.InsertTextInRun(" ");
e.Handled = true;
}
}
The problem is that the caret stays in place after the call to InsertTextInRun(). It does not move to the end of the new text, which is the behavior I want. How would I do this?
As an aside - yes, I know about the AcceptsTab property on RichTextBox. I'm choosing to ignore is and roll my own tab functionality because tabbing with AcceptsTab has a nasty side effect of indenting text on subsequent lines, which is not what I want.