javascriptetherpad

How to determine caret position in Etherpad immediately after keypress?


I'm working on an Etherpad-lite plugin providing special autocomplete while writing. I'm trying to update the list of autocomplete items as the user writes. My problem is that the caret position in aceEditEvent's context.rep.selStart and context.rep.selEnd is only updated in the first idleWorkTimer event after the keypress, which has a huge latency for this purpose.

The events in aceEditEvent happen like the following:

  1. handleKeyEvent - comes immediately (for keydown I guess), content.rep has the selection before keystroke
  2. handleKeyEvent - comes immediately (for keypress I guess), content.rep has the selection before keystroke
  3. handleKeyEvent - comes immediately (for keyup I guess), content.rep has the selection before keystroke
  4. idleWorkTimer - comes with up to 1s latency, content.rep has the selection after keystroke

So how do I get the new caret position without latency?


Solution

  • The answer is here: https://github.com/ether/etherpad-lite/issues/2015

    Basically this problem is still unsolved. As a workaround it's possible to use setTimeout after the event to have the right caret position.