Skip to content

Commit

Permalink
Fix editor theme if user changes color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
int-y1 authored and quantum5 committed Jan 2, 2025
1 parent 8cef2ca commit 2cbacc7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions martor/static/martor/js/martor.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,29 @@
this.each(function (i, obj) {
var mainMartor = $(obj);
var field_name = mainMartor.data('field-name');
var darkMode = isDarkMode();
var ace_theme = darkMode ? 'twilight' : 'github';
var textareaId = $('#id_' + field_name);
var editorId = 'martor-' + field_name;
var editor = ace.edit(editorId);
var editorConfig = JSON.parse(textareaId.data('enable-configs').replace(/'/g, '"'));

if (darkMode) {
mainMartor.find('.ui').addClass('inverted');
var setupTheme = function () {
if (isDarkMode()) {
mainMartor.find('.ui').addClass('inverted');
editor.setTheme('ace/theme/twilight');
}
else {
mainMartor.find('.ui').removeClass('inverted');
editor.setTheme('ace/theme/github');
}
}

setupTheme();
if ($('body').data('theme') === 'auto' && window.matchMedia) {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function () {
setupTheme();
});
}

editor.setTheme('ace/theme/' + ace_theme);
editor.getSession().setMode('ace/mode/markdown');
editor.getSession().setUseWrapMode(true);
editor.$blockScrolling = Infinity; // prevents ace from logging annoying warnings
Expand Down

0 comments on commit 2cbacc7

Please sign in to comment.