diff --git a/src/adapters/interfaces.ts b/src/adapters/interfaces.ts index 696c780..310913a 100644 --- a/src/adapters/interfaces.ts +++ b/src/adapters/interfaces.ts @@ -33,9 +33,6 @@ export interface IVaultAdapter { // File modification modify(file: TFile, data: string): Promise; - - // File deletion (respects Obsidian trash settings) - trash(file: TAbstractFile, system: boolean): Promise; } /** diff --git a/src/adapters/vault-adapter.ts b/src/adapters/vault-adapter.ts index fbb819f..ca0e9bf 100644 --- a/src/adapters/vault-adapter.ts +++ b/src/adapters/vault-adapter.ts @@ -42,8 +42,4 @@ export class VaultAdapter implements IVaultAdapter { async modify(file: TFile, data: string): Promise { await this.vault.modify(file, data); } - - async trash(file: TAbstractFile, system: boolean): Promise { - await this.vault.trash(file, system); - } } \ No newline at end of file diff --git a/src/tools/note-tools.ts b/src/tools/note-tools.ts index 767ce29..5ca46e7 100644 --- a/src/tools/note-tools.ts +++ b/src/tools/note-tools.ts @@ -587,7 +587,8 @@ export class NoteTools { // Dry run - just return what would happen if (dryRun) { if (soft) { - destination = `.trash/${file.name}`; + // Destination depends on user's configured deletion preference + destination = 'trash'; } const result: DeleteNoteResult = { @@ -603,14 +604,13 @@ export class NoteTools { }; } - // Perform actual deletion + // Perform actual deletion using user's preferred trash settings + // FileManager.trashFile() respects the user's configured deletion preference + // (system trash or .trash/ folder) as set in Obsidian settings + await this.fileManager.trashFile(file); if (soft) { - // Move to trash using Obsidian's trash method - await this.vault.trash(file, true); - destination = `.trash/${file.name}`; - } else { - // Delete using user's preferred trash settings (system trash or .trash/ folder) - await this.fileManager.trashFile(file); + // For soft delete, indicate the file was moved to trash (location depends on user settings) + destination = 'trash'; } const result: DeleteNoteResult = { diff --git a/src/ui/notifications.ts b/src/ui/notifications.ts index 88635b9..e8e305f 100644 --- a/src/ui/notifications.ts +++ b/src/ui/notifications.ts @@ -163,7 +163,7 @@ export class NotificationManager { keyParams.push(`folder: "${this.truncateString(args.folder, 30)}"`); } if (args.recursive !== undefined) { - keyParams.push(`recursive: ${args.recursive}`); + keyParams.push(`recursive: ${String(args.recursive)}`); } // If no key params, show first 50 chars of JSON diff --git a/tests/note-tools.test.ts b/tests/note-tools.test.ts index 7d453dd..6279daa 100644 --- a/tests/note-tools.test.ts +++ b/tests/note-tools.test.ts @@ -436,15 +436,16 @@ describe('NoteTools', () => { const mockFile = createMockTFile('test.md'); (PathUtils.resolveFile as jest.Mock).mockReturnValue(mockFile); - mockVault.trash = jest.fn().mockResolvedValue(undefined); + mockFileManager.trashFile = jest.fn().mockResolvedValue(undefined); const result = await noteTools.deleteNote('test.md', true, false); expect(result.isError).toBeUndefined(); - expect(mockVault.trash).toHaveBeenCalledWith(mockFile, true); + expect(mockFileManager.trashFile).toHaveBeenCalledWith(mockFile); const parsed = JSON.parse(result.content[0].text); expect(parsed.deleted).toBe(true); expect(parsed.soft).toBe(true); + expect(parsed.destination).toBe('trash'); }); it('should permanently delete note', async () => { @@ -466,6 +467,7 @@ describe('NoteTools', () => { const mockFile = createMockTFile('test.md'); (PathUtils.resolveFile as jest.Mock).mockReturnValue(mockFile); + mockFileManager.trashFile = jest.fn().mockResolvedValue(undefined); const result = await noteTools.deleteNote('test.md', true, true); @@ -473,7 +475,8 @@ describe('NoteTools', () => { const parsed = JSON.parse(result.content[0].text); expect(parsed.deleted).toBe(false); expect(parsed.dryRun).toBe(true); - expect(mockVault.trash).not.toHaveBeenCalled(); + expect(parsed.destination).toBe('trash'); + expect(mockFileManager.trashFile).not.toHaveBeenCalled(); }); it('should return error if file not found', async () => { @@ -500,7 +503,7 @@ describe('NoteTools', () => { const mockFile = createMockTFile('test.md'); (PathUtils.resolveFile as jest.Mock).mockReturnValue(mockFile); - mockVault.trash = jest.fn().mockRejectedValue(new Error('Cannot delete')); + mockFileManager.trashFile = jest.fn().mockRejectedValue(new Error('Cannot delete')); const result = await noteTools.deleteNote('test.md');