Skip to content

Commit

Permalink
Trigger css-change one setting modification
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed May 27, 2023
1 parent 79849ba commit 54f4a50
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-style-settings",
"name": "Style Settings",
"version": "1.0.5",
"version": "1.0.6",
"minAppVersion": "0.11.5",
"description": "Offers controls for adjusting theme, plugin, and snippet CSS variables.",
"author": "mgmeyers",
Expand Down
38 changes: 20 additions & 18 deletions src/SettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,26 +470,28 @@ export class CSSSettingsManager {
);

this.styleTag.innerText = `
body.css-settings-manager {
${vars.reduce((combined, current) => {
return combined + `--${current.key}: ${current.value}; `;
}, '')}
}
body.theme-light.css-settings-manager {
${themedLight.reduce((combined, current) => {
return combined + `--${current.key}: ${current.value}; `;
}, '')}
}
body.theme-dark.css-settings-manager {
${themedDark.reduce((combined, current) => {
return combined + `--${current.key}: ${current.value}; `;
}, '')}
}
`
body.css-settings-manager {
${vars.reduce((combined, current) => {
return combined + `--${current.key}: ${current.value}; `;
}, '')}
}
body.theme-light.css-settings-manager {
${themedLight.reduce((combined, current) => {
return combined + `--${current.key}: ${current.value}; `;
}, '')}
}
body.theme-dark.css-settings-manager {
${themedDark.reduce((combined, current) => {
return combined + `--${current.key}: ${current.value}; `;
}, '')}
}
`
.trim()
.replace(/[\r\n\s]+/g, ' ');

this.plugin.app.workspace.trigger('css-change', { source: 'style-settings' });
}

setConfig(settings: ParsedCSSSettings[]) {
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ export default class CSSSettingsPlugin extends Plugin {
});

this.registerEvent(
this.app.workspace.on('css-change', () => {
this.parseCSS();
(this.app.workspace as any).on('css-change', (data?: { source: string }) => {
if (data?.source !== 'style-settings') {
this.parseCSS();
}
})
);

Expand Down

0 comments on commit 54f4a50

Please sign in to comment.