I am implementing a "change case" functionality for my RichTextBox like word has with Shift+F3. All it does is switching between lower->upper->title case, which is very simple once I get access to the string I need.
My question is, how to change (and find it in the first place) a string in flowdocument without losing any embedded elements (losing formatting is not a problem) that may be contained within the string. Same as word, I need this functionality for 2 cases:
1) Mouse-selected text. I tried simply
this.Selection.Text = newText;
But that of course lost my embedded elements.
2) The last word before caret position. Any non-text element is a word delimiter, however one word can be
"He<weird formatting begin>ll<weird formatting end>o".
SOLUTION
This way it mimics MS WORD Shift+F3 behaviour. Only problem that in very few cases occurs is the carret being moved to the word beginning instead of keeping its position. I suppose that a short sleep after EditingCommands.MoveLeftByWord.Execute(null, this); would fix this, but this would be a dirty hack and I am trying to find out a nicer solution.