Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
Restore Harper linter active/inactive status between sessions. (#1852)
iBenMoore73c6b0613579
diff --git a/packages/obsidian-plugin/src/HarperSettingTab.ts b/packages/obsidian-plugin/src/HarperSettingTab.tsindex b9c0dffc2..5cf8888db 100644--- a/packages/obsidian-plugin/src/HarperSettingTab.ts+++ b/packages/obsidian-plugin/src/HarperSettingTab.ts@@ -86,6 +86,16 @@ export class HarperSettingTab extends PluginSettingTab {});});+ new Setting(containerEl)+ .setName('Activate Harper')+ .setDesc('Enable or disable Harper with this option.')+ .addToggle((toggle) =>+ toggle.setValue(this.settings.lintEnabled).onChange(async (value) => {+ this.state.toggleAutoLint();+ this.plugin.updateStatusBar();+ }),+ );+new Setting(containerEl).setName('Personal Dictionary').setDesc(diff --git a/packages/obsidian-plugin/src/State.ts b/packages/obsidian-plugin/src/State.tsindex d3e036a20..0339ce077 100644--- a/packages/obsidian-plugin/src/State.ts+++ b/packages/obsidian-plugin/src/State.ts@@ -14,6 +14,7 @@ export type Settings = {userDictionary?: string[];delay?: number;ignoredGlobs?: string[];+ lintEnabled?: boolean;};const DEFAULT_DELAY = -1;@@ -28,6 +29,7 @@ export default class State {private onExtensionChange: () => void;private ignoredGlobs?: string[];private editorViewField?: StateField<MarkdownFileInfo>;+ private lintEnabled?: boolean;/** The CodeMirror extension objects that should be inserted by the host. */private editorExtensions: Extension[];@@ -49,7 +51,11 @@ export default class State {public async initializeFromSettings(settings: Settings | null) {if (settings == null) {- settings = { useWebWorker: true, lintSettings: {} };+ settings = {+ useWebWorker: true,+ lintEnabled: true,+ lintSettings: {},+ };}const defaultConfig = await this.harper.getDefaultLintConfig();@@ -87,11 +93,12 @@ export default class State {this.delay = settings.delay ?? DEFAULT_DELAY;this.ignoredGlobs = settings.ignoredGlobs;+ this.lintEnabled = settings.lintEnabled;// Reinitialize it.if (this.hasEditorLinter()) {- this.disableEditorLinter();- this.enableEditorLinter();+ this.disableEditorLinter(false);+ this.enableEditorLinter(false);}await this.saveData(settings);@@ -218,6 +225,7 @@ export default class State {dialect: await this.harper.getDialect(),delay: this.delay,ignoredGlobs: this.ignoredGlobs,+ lintEnabled: this.lintEnabled,};}@@ -289,20 +297,25 @@ export default class State {}/** Enables the editor linter by adding an extension to the editor extensions array. */- public enableEditorLinter() {+ public enableEditorLinter(reinit = true) {if (!this.hasEditorLinter()) {this.editorExtensions.push(this.constructEditorLinter());+ this.lintEnabled = true;this.onExtensionChange();+ if (reinit) this.reinitialize();console.log('Enabled');}}/** Disables the editor linter by removing the extension from the editor extensions array. */- public disableEditorLinter() {+ public disableEditorLinter(reinit = true) {while (this.hasEditorLinter()) {this.editorExtensions.pop();}+ this.lintEnabled = false;this.onExtensionChange();+ if (reinit) this.reinitialize();+ console.log('Disabled');}public hasEditorLinter(): boolean {diff --git a/packages/obsidian-plugin/src/index.ts b/packages/obsidian-plugin/src/index.tsindex 4d9c8d7ed..51a63326a 100644--- a/packages/obsidian-plugin/src/index.ts+++ b/packages/obsidian-plugin/src/index.ts@@ -31,7 +31,9 @@ export default class HarperPlugin extends Plugin {this.registerEditorExtension(this.state.getCMEditorExtensions());this.setupCommands();this.setupStatusBar();- this.state.enableEditorLinter();+ if (!data.lintEnabled) {+ this.state.disableEditorLinter();+ } else this.state.enableEditorLinter();this.addSettingTab(new HarperSettingTab(this.app, this, this.state));}@@ -62,7 +64,7 @@ export default class HarperPlugin extends Plugin {const logo = document.createElement('span');logo.style.width = '24px';- logo.innerHTML = logoSvg;+ logo.innerHTML = this.state.hasEditorLinter() ? logoSvg : logoSvgDisabled;this.logo = logo;button.appendChild(logo);