Skip to content

Commit

Permalink
add setting for editor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenkuro committed Jul 29, 2023
1 parent 7e73b23 commit 0d5bcc9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 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-basetag",
"name": "Base Tag Renderer",
"version": "1.1.5",
"version": "1.1.6",
"minAppVersion": "0.15.0",
"description": "This plugin renders the basename of tags.",
"author": "Darren Kuro",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-basetag",
"version": "1.1.5",
"version": "1.1.6",
"description": "This plugin renders the basename for tags.",
"main": "main.js",
"scripts": {
Expand Down
46 changes: 44 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin } from "obsidian";
import { App, Plugin, PluginSettingTab, Setting } from "obsidian";
import { syntaxTree } from "@codemirror/language";
import { RangeSetBuilder } from "@codemirror/state";
import {
Expand Down Expand Up @@ -167,10 +167,13 @@ class editorPlugin implements PluginValue {
}

export default class TagRenderer extends Plugin {
public settings: SettingParams = DEFAULT_SETTING;

async onload() {
this.loadSettings();
this.registerEditorExtension(
ViewPlugin.fromClass(editorPlugin, {
decorations: (value) => value.decorations,
decorations: (value) => this.settings.renderOnEditor ? value.decorations: new RangeSetBuilder<Decoration>().finish(),
}),
);

Expand All @@ -186,5 +189,44 @@ export default class TagRenderer extends Plugin {
},
);
});
this.addSettingTab(new SettingTab(this.app, this));
}
async loadSettings() {
this.settings = Object.assign(DEFAULT_SETTING, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}

interface SettingParams {
renderOnEditor: boolean;
}

const DEFAULT_SETTING: SettingParams = {
renderOnEditor: true
};

class SettingTab extends PluginSettingTab {
constructor(public app: App, public plugin: TagRenderer) {
super(app, plugin);
}

async display() {
const { settings: setting } = this.plugin;
const { containerEl } = this;
containerEl.empty();

const editorSetting = new Setting(containerEl);
editorSetting
.setName("Render on Editor")
.setDesc("Render basetags also on editor.")
.addToggle((toggle) => {
toggle.setValue(setting.renderOnEditor);
toggle.onChange(async (value) => {
setting.renderOnEditor = value;
await this.plugin.saveSettings();
});
});
}
}

0 comments on commit 0d5bcc9

Please sign in to comment.