Skip to content

Commit

Permalink
Dark mode is preserved on refresh.
Browse files Browse the repository at this point in the history
Fixes #922
  • Loading branch information
cdsmith committed May 12, 2019
1 parent f4ad398 commit c6d8a65
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions web/js/codeworld.js
Expand Up @@ -130,6 +130,7 @@ async function init() {

function initCodeworld() {
const editor = document.getElementById('editor');
const darkMode = window.localStorage.getItem('darkMode') === 'true';

window.codeworldKeywords = {};

Expand All @@ -138,6 +139,8 @@ function initCodeworld() {
name: 'codeworld',
overrideKeywords: window.codeworldKeywords
},
theme: darkMode ? 'ambiance' : 'default',

undoDepth: 50,
lineNumbers: true,
autofocus: true,
Expand Down Expand Up @@ -325,6 +328,8 @@ function initCodeworld() {
window.codeworldEditor.on('cursorActivity', updateArgHelp);
window.codeworldEditor.on('refresh', updateArgHelp);

if (window.localStorage.getItem('darkMode') === 'true') toggleTheme();

CodeMirror.commands.save = cm => {
saveProject();
};
Expand Down Expand Up @@ -793,14 +798,12 @@ function moveHere() {
}

function toggleTheme() {
let root = document.getElementsByClassName('root')[0];
const root = document.getElementsByClassName('root')[0];
root.classList.toggle('dark-theme');
if (root.classList.contains('dark-theme')){
window.codeworldEditor.setOption('theme', 'ambiance');
} else {
window.codeworldEditor.setOption('theme', 'default');
}
}
const dark = root.classList.contains('dark-theme');
window.codeworldEditor.setOption('theme', dark ? 'ambiance' : 'default');
window.localStorage.setItem('darkMode', dark);
}

function changeFontSize(incr) {
return () => {
Expand Down

0 comments on commit c6d8a65

Please sign in to comment.