Skip to content

Commit

Permalink
only reset when compatibility mode is toggled
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebonsignori committed Oct 27, 2023
1 parent 2f2ba28 commit 45383c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,32 @@ export default class AtSymbolLinking extends Plugin {
)
);
} else {
this._suggestionPopup = new SuggestionPopup(this.app, this.settings);
this._suggestionPopup = new SuggestionPopup(
this.app,
this.settings
);
this.registerEditorSuggest(this._suggestionPopup);
applyHotKeyHack(this, this.app);
}
}

// Since we can disable/enable modes that register and unregister an editor extension in settings
// We need to reload the plugin to unregister the existing extension when settings are changed
async reloadPlugin() {
async reloadPlugin(shouldReset: boolean) {
if (!shouldReset) {
return;
}
if (this.reloadingPlugins) return;
this.reloadingPlugins = true;

const plugins = (<any>this.app).plugins;
if (!plugins?.enabledPlugins?.has(this.manifest.id)) return;
if (!plugins?.enabledPlugins?.has(this.manifest.id)) {
return;
}

await plugins.disablePlugin(this.manifest.id);
try {
await new Promise((resolve) => setTimeout(resolve, 100));
await plugins.enablePlugin(this.manifest.id);
} catch (error) {
/* empty */
Expand Down
6 changes: 5 additions & 1 deletion src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,18 @@ const arrayMove = <T>(array: T[], fromIndex: number, toIndex: number): void => {

export class SettingsTab extends PluginSettingTab {
plugin: AtSymbolLinking;
shouldReset: boolean;

constructor(app: App, plugin: AtSymbolLinking) {
super(app, plugin);
this.plugin = plugin;
this.shouldReset = false;
}

// On close, reload the plugin
hide() {
this.plugin.reloadPlugin();
this.plugin.reloadPlugin(this.shouldReset);
this.shouldReset = false;
}

display(): void {
Expand Down Expand Up @@ -286,6 +289,7 @@ export class SettingsTab extends PluginSettingTab {
toggle
.setValue(this.plugin.settings.useCompatibilityMode)
.onChange((value: boolean) => {
this.shouldReset = true;
this.plugin.settings.useCompatibilityMode = value;
this.plugin.saveSettings();
this.plugin.registerPopup();
Expand Down

0 comments on commit 45383c3

Please sign in to comment.