Merge pull request #21 from IdanLib/rewrite-move-to-forwards-folder-with-file-manager-api

improvements
This commit is contained in:
Idan Liberman 2024-12-04 23:22:27 +02:00 committed by GitHub
commit 98e43c3002
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 8 deletions

View file

@ -49,7 +49,7 @@ export default class RedirectSettingsTab extends PluginSettingTab {
button.setButtonText("Delete");
button.setTooltip("Delete the _forwards folder.");
button.setWarning();
button.onClick((evt) => {
button.onClick(async (evt) => {
const forwardsFolder =
this.app.vault.getFolderByPath("_forwards");
if (!forwardsFolder) {
@ -61,7 +61,7 @@ export default class RedirectSettingsTab extends PluginSettingTab {
}
try {
this.app.vault.delete(forwardsFolder, true);
await this.app.fileManager.trashFile(forwardsFolder);
new Notice(
"_forwards folder deleted successfully.",
2000

View file

@ -110,8 +110,6 @@ export default class RedirectPlugin extends Plugin {
private async moveRedirectNote(
redirectingNote: TFile | null
): Promise<TFile | void> {
let redirectingNoteInFolder = null;
if (!redirectingNote) {
return;
}
@ -121,7 +119,7 @@ export default class RedirectPlugin extends Plugin {
}
try {
redirectingNoteInFolder = await this.app.vault.copy(
const redirectingNoteInFolder = await this.app.vault.copy(
redirectingNote,
`/_forwards/${redirectingNote.name}`
);
@ -131,11 +129,10 @@ export default class RedirectPlugin extends Plugin {
this.app.workspace.off("file-open", this.redirectRef);
await this.app.workspace
.getLeaf(this.settings.openInNewTab)
.getLeaf()
.openFile(redirectingNoteInFolder, {
active: this.settings.switchToNewTab,
});
this.app.workspace.getLeaf().detach();
this.app.workspace.on("file-open", this.redirectRef);
}
@ -148,7 +145,7 @@ export default class RedirectPlugin extends Plugin {
private async deleteNote(orgRedirectingNote: TFile): Promise<void> {
try {
await this.app.vault.delete(orgRedirectingNote);
await this.app.fileManager.trashFile(orgRedirectingNote);
} catch (error) {
new Notice(
"Failed to delete directing note from original location. Please delete manually.",