【问题标题】:ACE Editor "end of parsing" eventACE 编辑器“解析结束”事件
【发布时间】:2014-09-22 21:21:51
【问题描述】:

我希望在 ACE 编辑器结束解析新源代码时回调一个函数,以便能够在每个后续的 .ace_identifier DOM 节点上添加一个单击事件侦听器。到目前为止,我找不到合适的 ACE 事件用于此,下面的简单代码没有做任何事情:

    editor = ace.edit $('#editor')
    editor.setReadOnly true

    // editor change event - never triggered in this case
    editor.getSession().on 'change', (e) ->
      console.log e

    // changing the language makes ACE parse the source code and generates
    // a new DOM...
    editor.getSession().setMode "ace/mode/javascript"
    // ... but a this point, $('.ace_identifier') returns a empty array
    // instead of the expected list of ace_identifiers created 
    console.log $('.ace_identifier')

【问题讨论】:

    标签: javascript ace-editor


    【解决方案1】:

    没有“解析结束”的事件,你可以在editor.renderer上使用afterRender事件,但是ace使用dom作为画布,只为文本的可见部分创建节点,并且经常丢弃和重绘整个事情,所以将事件监听器添加到 ace 编辑器内的 dom 节点是一个坏主意。

    您可以改为在编辑器中添加一个侦听器,并使用session.getToken 获取光标下的令牌。

    ace google 小组中的讨论可能会有所帮助https://groups.google.com/d/msg/ace-discuss/XFnf3-3gcAY/u7OIMdHkGGwJ

    【讨论】:

    • 使用afterRender 事件,我确实能够选择.ace_identifier DOM,但在其上设置点击事件处理程序不起作用。
    • 你可以添加pointer-events:auto 样式。但正如我所说,向每个节点添加事件处理程序是一个非常糟糕的主意,你应该使用 editor.on("click" listener 和 session.getToken 来代替。
    • 你怎么知道这个pointer-events设置为none!就因为这个,我花了这么多精力和时间!稍后我将使用优化的方式。这是迄今为止的原型设计。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    相关资源
    最近更新 更多