mirror of
https://github.com/mnaoumov/obsidian-smart-rename.git
synced 2026-07-22 07:40:32 +00:00
Refactor
This commit is contained in:
parent
8bb6e3d90d
commit
09d208dab4
4 changed files with 16 additions and 12 deletions
|
|
@ -1,11 +1,13 @@
|
|||
import SmartRenameSettingsTab from "./SmartRenameSettingsTab";
|
||||
import SmartRenameSettings from "./SmartRenameSettings";
|
||||
import { Notice,
|
||||
import {
|
||||
Notice,
|
||||
Plugin,
|
||||
TFile,
|
||||
LinkCache,
|
||||
parseFrontMatterAliases,
|
||||
CachedMetadata } from "obsidian";
|
||||
CachedMetadata
|
||||
} from "obsidian";
|
||||
import prompt from "./prompt";
|
||||
import { InvalidCharacterAction } from "./InvalidCharacterAction";
|
||||
|
||||
|
|
@ -87,7 +89,7 @@ export default class SmartRenamePlugin extends Plugin {
|
|||
.replace(/^((---\n(.|\n)+?---\n)?(.|\n)*\n)# .+/, `$1# ${titleToStore}`));
|
||||
}
|
||||
|
||||
this.newPath = `${this.currentNoteFile.parent.path}/${this.newTitle}.md`;
|
||||
this.newPath = `${this.currentNoteFile.parent!.path}/${this.newTitle}.md`;
|
||||
|
||||
const validationError = await this.getValidationError();
|
||||
if (validationError) {
|
||||
|
|
@ -191,7 +193,7 @@ export default class SmartRenamePlugin extends Plugin {
|
|||
}
|
||||
|
||||
private getLinksAndEmbeds(cache: CachedMetadata): LinkCache[] {
|
||||
const links = new Array<LinkCache>();
|
||||
const links: LinkCache[] = [];
|
||||
if (cache.links) {
|
||||
links.push(...cache.links);
|
||||
}
|
||||
|
|
@ -232,11 +234,11 @@ export default class SmartRenamePlugin extends Plugin {
|
|||
this.settings = Object.assign(new SmartRenameSettings(), await this.loadData());
|
||||
}
|
||||
|
||||
private async saveSettings(): Promise<void> {
|
||||
public async saveSettings(): Promise<void> {
|
||||
await this.saveData(this.settings);
|
||||
}
|
||||
|
||||
private hasInvalidCharacters(str: string): boolean {
|
||||
public hasInvalidCharacters(str: string): boolean {
|
||||
return this.systemForbiddenCharactersRegExp.test(str) || this.obsidianForbiddenCharactersRegExp.test(str);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { InvalidCharacterAction } from "./InvalidCharacterAction";
|
||||
|
||||
export default class SmartRenameSettings {
|
||||
public invalidCharacterAction: InvalidCharacterAction = InvalidCharacterAction.Error;
|
||||
public invalidCharacterAction = InvalidCharacterAction.Error;
|
||||
public replacementCharacter = "_";
|
||||
public shouldStoreInvalidTitle = true;
|
||||
public shouldUpdateTitleKey = false;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import { InvalidCharacterAction } from "./InvalidCharacterAction";
|
||||
import SmartRenamePlugin from "./SmartRenamePlugin";
|
||||
import { App,
|
||||
import {
|
||||
App,
|
||||
PluginSettingTab,
|
||||
Setting } from "obsidian";
|
||||
Setting
|
||||
} from "obsidian";
|
||||
|
||||
export default class SmartRenameSettingsTab extends PluginSettingTab {
|
||||
public plugin: SmartRenamePlugin;
|
||||
|
|
@ -108,8 +110,8 @@ export default class SmartRenameSettingsTab extends PluginSettingTab {
|
|||
new Setting(storeInvalidTitleSettingEl)
|
||||
.setName("Store invalid title")
|
||||
.setDesc("If enabled, stores title with invalid characters. If disabled, stores the sanitized version")
|
||||
.addToggle(togleComponent => {
|
||||
togleComponent
|
||||
.addToggle(toggleComponent => {
|
||||
toggleComponent
|
||||
.setValue(this.plugin.settings.shouldStoreInvalidTitle)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.shouldStoreInvalidTitle = value;
|
||||
|
|
|
|||
Loading…
Reference in a new issue