ACE编辑器”;解析结束”;事件

ACE Editor "end of parsing" event

本文关键字:结束 事件 ACE 编辑器      更新时间:2023-09-26

我希望在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')

没有"解析结束"的事件,可以在editor.renderer上使用afterRender事件,但ace使用dom作为画布,只为文本的可见部分创建节点,并且经常丢弃和重绘整个内容,因此在ace编辑器中向dom节点添加事件侦听器是个坏主意。

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

这场在谷歌王牌小组的讨论可能会有所帮助https://groups.google.com/d/msg/ace-discuss/XFnf3-3gcAY/u7OIMdHkGGwJ