I'd like to track the movement of the caret/cursor in a contenteditable. I'm not sure what's the best way to do this, though.
I'm currently listening for click, keydown, keyup. (keypress of course doesn't even fire for things like arrow keys or ctrl-x.)
While click works fine, the problem with keydown is that it's fired before the caret actually moves, so when I query the current document selection range, I get the old position and not the new one. But if I rely on keyup to get the updated position, it fires too late: the caret moves as soon as the key is pressed down, but the key is released an arbitrary time later.
This must be possible because things like CKeditor are able to do this. Any hints?