From c9d4d7663e19900124ad457ed79357d0d93ca0f1 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Thu, 20 Oct 2016 12:06:28 +0200 Subject: [PATCH] Simplify modeloading Analogous to I82d278920695be12aa80a79548abf8b8ce5445fd, make sure that we can lazy load any language that Ace supports. Not because we need it, but because it's the nicer way to do it. Change-Id: I19b8a31041814ac1273d62a24b5ed622fd91a7a8 --- extension.json | 3 ++- modules/jquery.codeEditor.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/extension.json b/extension.json index e890a7ea..ef0b0472 100644 --- a/extension.json +++ b/extension.json @@ -78,7 +78,8 @@ "ace/mode-json.js", "ace/mode-css.js", "ace/mode-lua.js", - "ace/ext-language_tools.js" + "ace/ext-language_tools.js", + "ace/ext-modelist.js" ] }, "ext.codeEditor.ace.modes": { diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js index 5e661aed..43584c45 100644 --- a/modules/jquery.codeEditor.js +++ b/modules/jquery.codeEditor.js @@ -324,7 +324,7 @@ * Sets up the iframe in place of the textarea to allow more advanced operations */ setupCodeEditor: function () { - var box, lang, basePath, container, editdiv, session, AceLangMode; + var box, lang, basePath, container, editdiv, session; box = context.$textarea; lang = mw.config.get( 'wgCodeEditorCurrentLanguage' ); @@ -388,9 +388,11 @@ mw.hook( 'codeEditor.configure' ).fire( session ); - ace.config.loadModule( 'ace/mode/' + lang, function () { - AceLangMode = ace.require( 'ace/mode/' + lang ).Mode; - session.setMode( new AceLangMode() ); + ace.config.loadModule( 'ace/ext/modelist', function ( modelist ) { + if ( !modelist || !modelist.modesByName[ lang ] ) { + lang = 'text'; + } + session.setMode( 'ace/mode/' + lang ); } ); // Use jquery.ui.resizable so user can make the box taller too