Skip to content

Commit

Permalink
Fix editor extension settings not properly reflected (#2091)
Browse files Browse the repository at this point in the history
* Fix editor extension settings not properly reflected

* Fix formatting

---------

Co-authored-by: RyotaUshio <ushio@ms.k.u-tokyo.ac.jp>
  • Loading branch information
RyotaUshio and RyotaUshio authored Oct 9, 2023
1 parent 7a2b6a1 commit 11f4715
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ export default class DataviewPlugin extends Plugin {
}
});

// editor extension for inline queries
if (this.settings.enableInlineDataview || this.settings.enableInlineDataviewJs) {
this.cmExtension = [inlinePlugin(this.app, this.index, this.settings, this.api)];
this.registerEditorExtension(this.cmExtension);
}
// editor extensions
this.cmExtension = [];
this.registerEditorExtension(this.cmExtension);
this.updateEditorExtensions();

// Dataview "force refresh" operation.
this.addCommand({
Expand Down Expand Up @@ -146,8 +145,6 @@ export default class DataviewPlugin extends Plugin {
});
})
);
this.registerEditorExtension(inlineFieldsField);
this.registerEditorExtension(replaceInlineFieldsInLivePreview(this.app, this.settings));
}

private debouncedRefresh: () => void = () => null;
Expand Down Expand Up @@ -183,6 +180,18 @@ export default class DataviewPlugin extends Plugin {
registered.sortOrder = priority;
}

public updateEditorExtensions() {
// Don't create a new array, keep the same reference
this.cmExtension.length = 0;
// editor extension for inline queries: enabled regardless of settings (enableInlineDataview/enableInlineDataviewJS)
this.cmExtension.push(inlinePlugin(this.app, this.index, this.settings, this.api));
// editor extension for rendering inline fields in live preview
if (this.settings.prettyRenderInlineFields) {
this.cmExtension.push(inlineFieldsField, replaceInlineFieldsInLivePreview(this.app, this.settings));
}
this.app.workspace.updateOptions();
}

/**
* Based on the source, generate a dataview view. This works by doing an initial parsing pass, and then adding
* a long-lived view object to the given component for life-cycle management.
Expand Down Expand Up @@ -324,9 +333,10 @@ class GeneralSettingsTab extends PluginSettingTab {
.setName("Enable Inline Field Highlighting")
.setDesc("Enables or disables visual highlighting / pretty rendering for inline fields.")
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.prettyRenderInlineFields)
.onChange(async value => await this.plugin.updateSettings({ prettyRenderInlineFields: value }))
toggle.setValue(this.plugin.settings.prettyRenderInlineFields).onChange(async value => {
await this.plugin.updateSettings({ prettyRenderInlineFields: value });
this.plugin.updateEditorExtensions();
})
);

this.containerEl.createEl("h2", { text: "Codeblock Settings" });
Expand Down

0 comments on commit 11f4715

Please sign in to comment.