Reputation: 823
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
Upvotes: 7
Views: 2430
Reputation: 87
In Ace v1.32.7
:
mode = editor.getOption('mode')
console.log(mode)
prints
ace/mode/javascript
Upvotes: 0
Reputation: 1614
The clean way to get this without any somersaults:
var mode = editor.session.mode;
Upvotes: 0
Reputation: 5213
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!
Upvotes: 4
Reputation: 1330
To retrieve the name of the mode you use:
editor.getSession().getMode().$id
Upvotes: 8