I want to set some background or foreground properties to the latest symbol in RichTextBox.
I tried getting the latest textrange by saving the caret position before the input and then getting the textrange like that: new TextRange(previousCaret, currentCaret)
.
However this is a bug-prone decision, because you can actually get 2 or more last symbols in case if the caret position wasn't updated in time (for example, you are typing very quickly and pressing the buttons at the same time)
Now, maybe I don't even have to get the latest symbol's TextRange? Are there other ways, like some built-in methods?
So, how do I change the latest symbol's properties properly?