mirror of
https://github.com/esm7/obsidian-vimrc-support.git
synced 2026-07-22 05:00:25 +00:00
Add setting to change file name closes #15
File can only be inside the vault for some reason.
This commit is contained in:
parent
8f8b163615
commit
4116fe9fbe
1 changed files with 16 additions and 1 deletions
17
main.ts
17
main.ts
|
|
@ -2,9 +2,11 @@ import { App, Plugin, TFile, MarkdownView, PluginSettingTab, Setting } from 'obs
|
|||
declare const CodeMirror: any;
|
||||
|
||||
interface Settings {
|
||||
VIMRC_NAME: string;
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: Settings = {
|
||||
VIMRC_NAME: ".obsidian.vimrc"
|
||||
}
|
||||
|
||||
export default class VimrcPlugin extends Plugin {
|
||||
|
|
@ -21,7 +23,7 @@ export default class VimrcPlugin extends Plugin {
|
|||
this.addSettingTab(new SettingsTab(this.app, this))
|
||||
|
||||
this.registerEvent(this.app.workspace.on('file-open', (file: TFile) => {
|
||||
const VIMRC_FILE_NAME = '.obsidian.vimrc';
|
||||
const VIMRC_FILE_NAME = this.settings.VIMRC_NAME;
|
||||
this.app.vault.adapter.read(VIMRC_FILE_NAME).
|
||||
then((lines) => this.readVimInit(lines)).
|
||||
catch(error => { console.log('Error loading vimrc file', VIMRC_FILE_NAME, 'from the vault root') });
|
||||
|
|
@ -144,5 +146,18 @@ class SettingsTab extends PluginSettingTab {
|
|||
containerEl.empty();
|
||||
|
||||
containerEl.createEl('h2', {text: 'Obsidian Vimrc Support Settings'});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Vimrc file name')
|
||||
.setDesc('Relative to vault directory (requires restart)')
|
||||
.addText((text) => {
|
||||
text.setPlaceholder(DEFAULT_SETTINGS.VIMRC_NAME);
|
||||
if(this.plugin.settings.VIMRC_NAME !== DEFAULT_SETTINGS.VIMRC_NAME)
|
||||
text.setValue(this.plugin.settings.VIMRC_NAME)
|
||||
text.onChange(value => {
|
||||
this.plugin.settings.VIMRC_NAME = value || DEFAULT_SETTINGS.VIMRC_NAME;
|
||||
this.plugin.saveSettings();
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue