How do I find the text cursor's x/y coordinates?

  • Question
  • Updated 4 years ago
Whenever the selection range is collapsed, I want to show a little hover-dialog type of thing with some options depending on where the text entry position is and I would like to position it right above (or below) the caret. The closest / most similar thing I can think of would be the little copy/paste thing that pops up on iOS devices.

The only way I can think of to get the top and left coordinates would be to add an invisible little span element similar to what already happens with br.GENTICS_ephemera, get the position using jquery and then hide it again later.

Is there a better/simpler way?
Photo of lerouxbL

lerouxb

  • 2 Posts
  • 0 Likes

Posted 4 years ago

  • 1
Photo of c.prerovsky

c.prerovsky, Core Developer

  • 21 Posts
  • 2 Likes
Hi,

we also have that issue for positioning the Floating Menu - there is no way (or at least none I know of) to find the cursor's position. Inserting a DOM element next to the cursor was too dirty for my taste, so we used the parent block element as a fallback.
Photo of lerouxbL

lerouxb

  • 2 Posts
  • 0 Likes
Aah thanks. It is very dirty, but I think I might have to do it that way. Oh well.