How do I find currently loaded mode (syntax) in Ace Editor?

冷暖自知 提交于 2019-12-08 22:13:20

问题


Well as the title says - how do I find out what the currently loaded mode is in Ace Editor?

editor.getSession().getMode() does not really return anything I can use - have looked through the objects returned somewhat - but could not find anything.

editor.getTheme() returns a string to me that I can use however - just seems funny if they did not do somewhat the same for mode


回答1:


To retrieve the name of the mode you use:

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



回答2:


I tried Hugeen's answer and experienced the undefined error just like lorefnon reported. This is what worked for me:

// 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);

Hope that helps someone!



来源:https://stackoverflow.com/questions/10516988/how-do-i-find-currently-loaded-mode-syntax-in-ace-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!