首页 > 解决方案 > 为什么 ace 编辑器不发出 tokenizerUpdate 事件

问题描述

我里面有这段代码 compositionComplete()

this.docEditor = aceEditorBindingHandler.getEditorBySelection($(docEditorSelector);
// this.docEditor is of type AceAjax.Editor

if (this.docEditor) {
        this.docEditor.getSession().on("tokenizerUpdate", () => {
            // do stuff
        });
    }

但它永远不会被击中。

如果我将事件更改为“ change”,则内容更改时会触发代码。
但这不是我需要的。

任何想法 ?有人吗?

标签: javascriptdurandalace-editor

解决方案


类似于 change 事件,tokenizer 更新不会被同步调用。有关其工作的演示,请参见下面的示例。

<script src=https://ajaxorg.github.io/ace-builds/src-noconflict/ace.js></script>

<script>
  editor = ace.edit(null, {
    mode: "ace/mode/javascript",
    minLines: 5,
    maxLines: 10,
  })
  var log = ace.edit(null, {
    mode: "ace/mode/javascript",
    minLines: 5,
    maxLines: 10,
  })

  document.documentElement.appendChild(editor.container)
  document.documentElement.appendChild(log.container)
  editor.session.on("tokenizerUpdate", () => {
    log.insert("tokenizerUpdate called " + Date.now() + "\n")
  })
</script>


推荐阅读