Skip to content

Commit

Permalink
✨ Reload styles on external config change
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Dec 4, 2023
1 parent 645eefc commit 620f4df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/@types/settings.d.ts
Expand Up @@ -12,3 +12,10 @@ export interface SWSettings {
showAllWhitespace: boolean;
outlineListMarkers: boolean;
}

declare module "obsidian" {
interface Plugin {
onConfigFileChange: () => void;
handleConfigFileChange(): Promise<void>;
}
}
21 changes: 16 additions & 5 deletions src/whitespace-Plugin.ts
@@ -1,4 +1,4 @@
import { Plugin } from "obsidian";
import { Plugin, debounce } from "obsidian";
import {
highlightTrailingWhitespace,
highlightWhitespace,
Expand Down Expand Up @@ -67,11 +67,22 @@ export class ShowWhitespacePlugin extends Plugin {
}

onunload(): void {
console.log("unloading Show Whitespace (SW-CM6)");
console.log("(SW-CM6) unloading Show Whitespace");
document.body.classList.add(this.manifest.id);
this.removeClasses();
}

async handleConfigFileChange() {
await super.handleConfigFileChange();
this.onExternalSettingsChange();
}

public onExternalSettingsChange = debounce(async () => {
this.removeClasses();
this.initClasses();
console.debug("(SW-CM6) external settings changed");
}, 2000, true);

async loadSettings(): Promise<void> {
if (!this.settings) {
const options = await this.loadData();
Expand All @@ -89,13 +100,13 @@ export class ShowWhitespacePlugin extends Plugin {
async updateSettings(newSettings: SWSettings): Promise<void> {
this.settings = Object.assign({}, this.settings, newSettings);
await this.saveSettings();
this.removeClasses();
this.initClasses();
console.log("(SW-CM6) settings and classes updated");
}

async saveSettings(): Promise<void> {
console.debug("(SW-CM6): saving settings");
await this.saveData(this.settings);
this.removeClasses();
this.initClasses();
}
}

Expand Down

0 comments on commit 620f4df

Please sign in to comment.