Skip to content

Commit

Permalink
fix: 修复changeTheme无法新增theme的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
eyebrowkang committed Nov 21, 2023
1 parent 9904922 commit 1c7b949
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ export function getThemeFromLocal(fullClass = false) {
*/
export function changeTheme($cherry, theme = '') {
const newTheme = (theme ? theme : getThemeFromLocal()).replace(/^.*theme__/, '');
const reg = /(\stheme__)([^ $]+?)( |$)/g;
const replacer = (match, p1, p2, p3) => {
return `${p1}${newTheme}${p3}`;
const newClass = ` theme__${newTheme}`;
const reg = /(\stheme__[^\s$]+?)(\s|$)/g;
const replacer = (match, p1, p2) => {
return p2;
};
$cherry.wrapperDom.className = $cherry.wrapperDom.className.replace(reg, replacer);
$cherry.previewer.getDomContainer().className = $cherry.previewer.getDomContainer().className.replace(reg, replacer);
$cherry.wrapperDom.className = $cherry.wrapperDom.className.replace(reg, replacer) + newClass;
$cherry.previewer.getDomContainer().className =
$cherry.previewer.getDomContainer().className.replace(reg, replacer) + newClass;
saveThemeToLocal(newTheme);
}

0 comments on commit 1c7b949

Please sign in to comment.