[themes] fix theme flashing when multiple editors open

This commit is contained in:
Maxim Kadushkin 2022-07-11 23:57:29 +03:00
parent 2dfad6b6fa
commit 06deb0f09d

View file

@ -413,10 +413,11 @@ define([
Common.NotificationCenter.trigger('contenttheme:dark', !is_current_dark); Common.NotificationCenter.trigger('contenttheme:dark', !is_current_dark);
}, },
setTheme: function (obj, force) { setTheme: function (obj) {
if ( !obj ) return; if ( !obj ) return;
var id = get_ui_theme_name(obj); var id = get_ui_theme_name(obj),
refresh_only = arguments[1];
if ( is_theme_type_system(id) ) { if ( is_theme_type_system(id) ) {
Common.localStorage.setBool('ui-theme-use-system', true); Common.localStorage.setBool('ui-theme-use-system', true);
@ -425,7 +426,7 @@ define([
Common.localStorage.setBool('ui-theme-use-system', false); Common.localStorage.setBool('ui-theme-use-system', false);
} }
if ( (this.currentThemeId() != id || force) && !!themes_map[id] ) { if ( (this.currentThemeId() != id || refresh_only) && !!themes_map[id] ) {
document.body.className = document.body.className.replace(/theme-[\w-]+\s?/gi, '').trim(); document.body.className = document.body.className.replace(/theme-[\w-]+\s?/gi, '').trim();
document.body.classList.add(id, 'theme-type-' + themes_map[id].type); document.body.classList.add(id, 'theme-type-' + themes_map[id].type);
@ -456,10 +457,12 @@ define([
theme_obj.colors = obj; theme_obj.colors = obj;
} }
Common.localStorage.setItem('ui-theme', JSON.stringify(theme_obj)); if ( !refresh_only )
Common.localStorage.setItem('ui-theme', JSON.stringify(theme_obj));
} }
Common.localStorage.setItem('ui-theme-id', id); if ( !refresh_only )
Common.localStorage.setItem('ui-theme-id', id);
Common.NotificationCenter.trigger('uitheme:changed', id); Common.NotificationCenter.trigger('uitheme:changed', id);
} }
}, },