问题
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