Hi,
Here is what I'm trying achieve:
As you know, some characters are RTL and some are LTR, but some are "weak" and take on the directionality of their neighbors. This includes delimiters and punctuation among other things. When the user is typing (only in an RTL language, like Arabic, of course) and any of the set of characters that have "weak" directionality are typed, I want to put a Unicode marker characters (either LTR 0x8206 or RTL 0x8206) either before or after that character to give it a strong orientation.
Since we really have bidirectional text, we want some "weak" characters to behave as RTL and others to behave as LTR. For example we have keywords inside curly braces that will always be English, while the rest of the text, including text inside parentheses or square brackets will all be Arabic. So to keep things displaying propery (especially at the end-of-line scenario), I want to put RTL markers near the parenthesis and square brackets and put LTR markers near the curly braces. An example might look like this:
ش (ب|غ) شىي {restaurant} سي
In this case, we'd want the RTL marker before the "(" and after the ")" and the LTR marker before the "{" and after the "}". We could also have those keywods inside the parentheses by the way, as one of the choices separated by the pipe.
These "weak" characters really behave badly when they have some Arabic text on one side and English text on the other, so it is necessary to tell them what their allegiance is. Given our language scheme, we know which weak characters should behave as RTL and which should behave as LTR and the markers provide that buffer from the nearby text that is oriented differently.
I think this could be achieved while the user types, but probably also needs to be re-done on the current state of the text to deal proprly with deletes/replacements/pastes, etc. Given that, perhaps it is better not to do it on the fly, but instead fix up the text after changes? If so, what would be the best place and/or recommended method to do that?
Additionally, I need to properly handle left-right arrow navigation, so that we don't have to hit the key twice to get past the invisible marker character. Adjusting the Caret location in OnKeyUp for Key.Right and Key.Left may be sufficient to handle this.
FYI, the English keywords mentioned above are already implmented with an auto-completer, so that when you type the initial curly, you get the dropdown and choose one to use. So you really don't need to switch the keyboard back to EN in order to get mixed bidirectional text. However, when this auto-completion occurs, ideally what I'd get inserted into the text would be surrounded by the LTR markers, so instead of "{navigate}" it would be "\x8206{navigate}\x8206".