Skip to content

Commit

Permalink
Rename the existing notes folder on settings change
Browse files Browse the repository at this point in the history
This avoids confusion when we already have an existing folder of synced
notes and the user changes the "Notes Folder" setting to a new value.
  • Loading branch information
jparise committed Jan 18, 2024
1 parent 0209709 commit eacfb84
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, ButtonComponent, Modal, PluginSettingTab, Setting, TextComponent, normalizePath } from "obsidian";
import { App, ButtonComponent, Modal, PluginSettingTab, Setting, TFolder, TextComponent, normalizePath } from "obsidian";
import InstapaperPlugin from "./main";
import type { InstapaperAccessToken, InstapaperAccount } from "./api";

Expand Down Expand Up @@ -42,11 +42,18 @@ export class InstapaperSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Notes folder')
.setDesc('Folder in which notes and highlights will be synced')
.setDesc('Folder in which your notes and highlights will be synced')
.addText((text) => {
text.setValue(this.plugin.settings.notesFolder)
text.onChange(async (value) => {
await this.plugin.saveSettings({ notesFolder: normalizePath(value) });
const previousPath = this.plugin.settings.notesFolder;
const newPath = normalizePath(value);
await this.plugin.saveSettings({ notesFolder: newPath });

const previousFile = this.app.vault.getAbstractFileByPath(previousPath);
if (previousFile instanceof TFolder) {
await previousFile.vault.rename(previousFile, newPath);
}
})
});

Expand Down

0 comments on commit eacfb84

Please sign in to comment.