【问题标题】:How do I find currently loaded mode (syntax) in Ace Editor?如何在 Ace Editor 中找到当前加载的模式(语法)?
【发布时间】:2012-05-09 13:19:52
【问题描述】:

正如标题所说 - 我如何找出 Ace Editor 中当前加载的模式是什么?

editor.getSession().getMode() 并没有真正返回任何我可以使用的东西 - 已经查看了一些返回的对象 - 但找不到任何东西。

editor.getTheme() 返回一个字符串给我,但我可以使用 - 如果他们对模式没有做同样的事情,这似乎很有趣

【问题讨论】:

    标签: ace-editor


    【解决方案1】:

    要检索您使用的模式的名称:

    editor.getSession().getMode().$id
    

    【讨论】:

    • 是的,去ace.ajax.org/#nav=about打开Firebug(或随机控制台)并执行以下行:editor.getSession().getMode().$id
    【解决方案2】:

    我尝试了 Hugeen 的回答并遇到了 undefined 错误,就像 lorefnon 报告的那样。这对我有用:

    // get the editor instance
    var editor = ace.edit('editorid');
    
    // get the current mode
    var mode = editor.session.$modeId;
    
    // modeid returns the full string (ace/mode/html), cut to the mode name only
    mode = mode.substr(mode.lastIndexOf('/') + 1);
    

    希望对某人有所帮助!

    【讨论】:

    • 如果我在浏览器中尝试.getMode().$id,一切都很好,但如果我在我的代码中做同样的事情就不行了。 $modeId 但是效果很好!知道可能是什么原因吗? getMode() 是否可能返回初始模式设置而不是当前设置?
    【解决方案3】:

    没有任何翻筋斗的干净方法:

    var mode = editor.session.mode;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多