Skip to content

Commit 3cc8752

Browse files
committed
feat: add delete file
1 parent 1098c00 commit 3cc8752

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/svelte/index.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script lang="ts">
22
import { Menu, type App } from "obsidian";
3+
import { deleteFile } from "src/utils/delete-file";
34
import { findDuplicateUrls } from "src/utils/find-duplicate-urls";
4-
import { openInNewTab, openToTheRight } from "src/utils/open-file-utils";
5+
import { openInNewTab, openToTheRight } from "src/utils/open-file";
56
import { onMount } from "svelte";
67
78
interface AppProps {
@@ -27,6 +28,14 @@
2728
item.setTitle("Open to the right");
2829
item.onClick(() => openToTheRight(obsidianApp, filePath));
2930
});
31+
menu.addSeparator();
32+
menu.addItem((item) => {
33+
item.setTitle("Delete file");
34+
item.onClick(async () => {
35+
await deleteFile(obsidianApp, filePath);
36+
duplicateUrls = await findDuplicateUrls(obsidianApp);
37+
});
38+
});
3039
menu.showAtMouseEvent(event);
3140
}
3241

src/utils/delete-file.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { App, Notice } from "obsidian";
2+
3+
export const deleteFile = async (app: App, filePath: string) => {
4+
const file = app.vault.getFileByPath(filePath);
5+
if (file) {
6+
await app.vault.delete(file);
7+
} else {
8+
new Notice("Cannot delete file, file not found");
9+
}
10+
};
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import type { App } from "obsidian";
2-
3-
export const openToTheRight = (app: App, filePath: string) => {
4-
app.workspace.openLinkText(filePath, "", "split", {
5-
active: false,
6-
});
7-
};
1+
import { type App } from "obsidian";
82

93
export const openInNewTab = async (
104
app: App,
@@ -24,3 +18,9 @@ export const openInNewTab = async (
2418
active,
2519
});
2620
};
21+
22+
export const openToTheRight = (app: App, filePath: string) => {
23+
app.workspace.openLinkText(filePath, "", "split", {
24+
active: false,
25+
});
26+
};

0 commit comments

Comments
 (0)