# Position cursor at approximate area while clicking on preview

This feature request is to position cursor at appropriate place i.e. the corresponding place where the mouse pointer is clicked over the preview of the post.

This would be helpful while asking the question and more helpful while editing long post (or post that contain long piece of code).

I created a gif(not a great one, but learn't to create a gif to demonstrate this ;)) to explain this. If we click at point A the cursor should be placed at the <?php line in the text-area, if mouse pointer is clicked at point B, then the cursor should be placed at it's respective position in text-area.

-
+1 for suggestion, -1 for yellow text on gray background –  Jeff Nov 24 '12 at 21:33
Holy shmoly, thanks, @animuson (If I could upvote edits...). –  Daniel Fischer Nov 24 '12 at 21:42
Thanks @animuson. But had thought a gif would be more appealing in this case. –  mtk Nov 25 '12 at 8:16

A feature like this would be quite difficult to implement I imagine, particularly because it is unprecedented.

The current state of DOM API doesn't give you anything that lets you detect what two characters a click occurred between, which means you're stuck either using unreliable coordinate based checks or adding a wrapping element + hook to each and every character in the body of your text.

Here are a few proposals for more realistic requirements:

1. Navigate to the beginning of the relevant code block, quote or text run on click.
2. Navigate on drag selection instead of on click, which is much easier to implement
-
It is possible to get the selected text in most browsers, though not on a standard way. So this could be made to work if it was match selection rather than just location. –  EdC Nov 25 '12 at 8:50
@EdC Yes, that is why I proposed the second alternative. Constructing a range from the selection and processing it shouldn't be too difficult. –  Asad Nov 25 '12 at 8:56

This is close to impossible to get really right, but I have a userscript that tries to come as close as possible: Dude, where's my cursor?.

It comes with a few caveats, so be sure to read the description.

-