按键后如何立即确定插入符号在 Etherpad 中的位置?

How to determine caret position in Etherpad immediately after keypress?

我正在开发一个 Etherpad-lite 插件,在编写时提供特殊的自动完成功能。我正在尝试在用户写入时更新自动完成项目列表。我的问题是 aceEditEvent 的 context.rep.selStart 和 context.rep.selEnd 中的插入符位置仅在按键后的第一个 idleWorkTimer 事件中更新,为此目的有很大的延迟。

aceEditEvent 中的事件如下所示:

  1. handleKeyEvent - 立即出现(我猜是针对 keydown),content.rep 有选择 before keystroke
  2. handleKeyEvent - 立即出现(我猜是按键),content.rep 有选择 before keystroke
  3. handleKeyEvent - 立即出现(我猜是为 keyup),content.rep 有选择 before keystroke
  4. idleWorkTimer - 最多延迟 1 秒,content.rep 有选择 after keystroke

那么如何在没有延迟的情况下获得新的插入符位置?

答案在这里: https://github.com/ether/etherpad-lite/issues/2015

基本上这个问题还是没有解决。作为解决方法,可以在事件发生后使用 setTimeout 来获得正确的插入符号位置。