Skip to content

Commit cb0d42f

Browse files
authored
Added Ace Editor Theme Support 🔧
1 parent 6316d62 commit cb0d42f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/code-runner-wc.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ function handleclick(codeRunner){
396396
document.body.appendChild(gfgData);
397397
});
398398
};
399-
let gfgScript = ['https://cdn.jsdelivr.net/npm/[email protected]/ace.min.js', 'https://cdn.jsdelivr.net/npm/[email protected]/ext-modelist.js']
399+
let gfgScript = ['https://cdn.jsdelivr.net/npm/[email protected]/ace.min.js', 'https://cdn.jsdelivr.net/npm/[email protected]/ext-modelist.js', "https://cdn.jsdelivr.net/npm/[email protected]/ext-themelist.js"]
400400
let promiseData = [];
401401

402402

@@ -445,7 +445,30 @@ var editor = ace.edit(html_element.querySelector("#codetorun"));
445445

446446
editor.$blockScrolling = Infinity;
447447

448+
// allow the Ace Editor theme to be changed.
449+
if (typeof CodeRunner_AceEditor_Theme == "undefined"){
448450
editor.setTheme("ace/theme/monokai");
451+
} else{
452+
453+
var themelist = ace.require("ace/ext/themelist")
454+
455+
var themes = themelist.themesByName //object hash of theme objects by name
456+
457+
// check if theme name is valid.
458+
if(themes[CodeRunner_AceEditor_Theme.toLowerCase()] != undefined) {
459+
460+
editor.setTheme(`ace/theme/${CodeRunner_AceEditor_Theme.toLowerCase()}`);
461+
} else{
462+
//
463+
/// Theme choice was not valid
464+
console.log(`Code Runner Error: ${CodeRunner_AceEditor_Theme} is not a valid theme - setting to default.`)
465+
466+
467+
editor.setTheme("ace/theme/monokai");
468+
469+
}
470+
}
471+
449472
if (language){
450473
SetAceEditor_Mode()
451474
}
@@ -483,7 +506,7 @@ editor.setOptions({
483506
async function CreateAceEditorForPlugin(element, language){
484507

485508
// make sure the editor is only set for non-terminal.
486-
if (!element.getAttribute("custom-compiler").includes("shell") && !element.getAttribute("custom-compiler").includes("terminal")){
509+
if (!element.getAttribute("custom-compiler").includes("shell") || !element.getAttribute("custom-compiler").includes("terminal")){
487510
// load ace editor for custom compiler plugin
488511
// Wait till AceEditor is loaded - so no errors occur.
489512

0 commit comments

Comments
 (0)