如何在 Etherpad 插件中捕获点击事件

How to catch click events in an Etherpad plugin

我正在开发一个 etherpad 插件,它在文本编辑期间提供特殊的自动完成功能。为此,我需要知道用户的插入符号在哪里。但是我不知道用户是否通过单击鼠标移动插入符号,因为我找不到合适的挂钩。

作为解决此问题的第一步,我想捕获鼠标单击事件。 (如果我能捕捉到点击事件,我仍然不确定如何找出插入符号的位置,但至少我知道何时处理它。)感谢任何帮助。

来自 ep_tasklist 插件 - https://raw.githubusercontent.com/JohnMcLear/ep_tasklist/master/static/js/ace_inner.js 稍作修改,将其用作您要完成的工作的参考点。

只需将点击侦听器事件绑定到内部文档正文

exports.postAceInit = function(hook, context){
  context.ace.callWithAce(function(ace){
    var doc = ace.ace_getDocument();
    $(doc).find('#innerdocbody').on("click", underscore(SOMEFUNCTIONINCORRECTCONTEXT).bind(ace));
  }, 'myPlugin', true);
}

我假设您也需要保留 ace 的上下文,否则您不需要使用下划线绑定功能。浏览器

exports.postAceInit = function(hook, context){
  context.ace.callWithAce(function(ace){
    var doc = ace.ace_getDocument();
    $(doc).find('#innerdocbody').on("click", function(){
       console.log("hello world")
    });
  }, 'myPlugin', true);
}