Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
43
rated 0 times [  44] [ 1]  / answers: 1 / hits: 13435  / 10 Years ago, thu, april 24, 2014, 12:00:00

I'm attempting to implement Ace Code Editor with a drop down to select the language. My drop down has an id of mode. I have got the editor to work correctly, but I cannot change the language using the drop down as I would like it to do. My current code is



var editor = ace.edit(code);
var textarea = $('textarea[name=code]').hide();
editor.setTheme(ace/theme/textmate);
editor.getSession().setMode(ace/mode/sql);
editor.getSession().setValue(textarea.val());
editor.getSession().on('change', function(){
textarea.val(editor.getSession().getValue());
});

$('#mode').on('change', function(){
var newMode = $(mode).val();
editor.session().setMode({
path: ace/mode/ + newMode,
v: Date.now()});
});


As above, this successfully launches the editor, however I can't change the language from SQL, which is the initial language. I came across this question Dynamically update syntax highlighting mode rules for the Ace Editor
which is why I've included



v: Date.now()


but still no luck.


More From » jquery

 Answers
4

you have a typo in the editor.session().setMode({ line



use editor.session.setMode(ace/mode/ + newMode) instead of it.



v: Date.now() was needed to disable caching, you most likely do not need that.


[#45777] Wednesday, April 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breap

Total Points: 606
Total Questions: 96
Total Answers: 108

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
breap questions
Thu, Jun 24, 21, 00:00, 3 Years ago
Wed, Mar 18, 20, 00:00, 4 Years ago
Mon, Oct 7, 19, 00:00, 5 Years ago
;