This mainly is related to how an editor uses Left to Right Mark (LRM) unprintable Unicode character u+200E. In case that somebody knows Persian, I have addressed the issue and a solution with complete details in here. I will try to give a summary of that solution, which is for TeXstudio. The main idea is to use Trigger for calling macros. Triggers are indeed regular expressions.
Make sure your Bi-Di setting in TeXstudio is as follows. You can access this setting through Options -> Configure TeXstudio -> Adv. Editor -> Bi-Di.

Create the following two macros via Macros -> Edit Macros. The first one is for handling inline equations as shown below. You should type $.$ for writing an inline equation, then the macro is called automatically, and replaces that with LRM$$LRM and places the cursor at the middle of the dollar signs. Now, inline equations will look as you expect. Here, the Trigger is
\$\.\$
and the corresponding script is
%SCRIPT
editor.write("\u200E$$\u200E")
cursor.shift(-2)

The second one is for handling inline commands like \lr and \text.... As we have disabled automatic insertion of LRM character by TeXstudio, we should also take care of inline commands to look right. Here, I have set the Trigger to
\\((text.+)|(lr))\{.*\}
and the corresponding script is
%SCRIPT
editor.write("\u200E");
editor.write(triggerMatches[0]);
editor.write("\u200E");
var pos = cursor.columnNumber();
cursor.selectColumns(pos, pos + 1);
cursor.removeSelectedText();

You may find a better regular expression the covers more cases but this does the job for me. Now, as you type closing curly bracket, in for example \lr{RTL-text}, the macro is called and encloses the whole inline command with LRM so the result is LRM\lr{RTL-text}LRM. Notice that if you use the auto-completer, you should type } to trigger the macro. If you press → to pass over the inserted } by the auto-completer then the macro is not triggered.
Now, everything should work fine as the following video shows. Here, I am typing in Persian.

$next to each other without some invisible markup. – Joseph Wright May 29 '19 at 06:37$next to each other without any invisible markup. – Moshe Gueta May 29 '19 at 07:46