Hello FABad
Davide will no doubt have a more sophisticated way of going about this, but the following demo is a rough start for what you're trying to do.
It's a proof of concept, and works for things like numbers and variables (a...z), and some symbols like square root and integral, but not for Greek letters or no doubt many other math entities.
It works by identifying the content of the clicked math item, then finding what's the index of that item (it could be say, the third 'x" in the expression), then goes looking for the 3rd "x" in the text box, and puts the cursor there.
It falls over for things like "sin" since if you click on the "i" it will find the first "i" in the text box, not the first "\sin".
But if you really need something that moves the cursor to the appropriate part of the input expression, it could be a starting point for you.
Here's the demo:
Hope it helps
Regards
Murray