From 9d3b311ca7788f73f280b501aec3de867115f5f2 Mon Sep 17 00:00:00 2001 From: Reorx Date: Mon, 9 May 2022 00:40:14 +0800 Subject: [PATCH] await each renameFunc so that the deduplication mechanism could work --- src/batch.ts | 10 ++++++---- src/main.ts | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/batch.ts b/src/batch.ts index dec9fdd..b29f6ff 100644 --- a/src/batch.ts +++ b/src/batch.ts @@ -16,13 +16,15 @@ interface RenameTask { name: string } +type renameFuncType = (file: TFile, name: string) => Promise + export class ImageBatchRenameModal extends Modal { activeFile: TFile - renameFunc: (file: TFile, name: string) => void + renameFunc: renameFuncType onCloseExtra: () => void state: State - constructor(app: App, activeFile: TFile, renameFunc: (file: TFile, name: string) => void, onClose: () => void) { + constructor(app: App, activeFile: TFile, renameFunc: renameFuncType, onClose: () => void) { super(app); this.activeFile = activeFile this.renameFunc = renameFunc @@ -170,10 +172,10 @@ export class ImageBatchRenameModal extends Modal { this.onCloseExtra() } - renameAll() { + async renameAll() { debugLog('renameAll', this.state) for (const task of this.state.renameTasks) { - this.renameFunc(task.file, task.name) + await this.renameFunc(task.file, task.name) } } diff --git a/src/main.ts b/src/main.ts index 7c2c5ea..db6c9bd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -191,8 +191,8 @@ export default class PasteImageRenamePlugin extends Plugin { const modal = new ImageBatchRenameModal( this.app, activeFile, - (file: TFile, name: string) => { - this.renameFile(file, name, activeFile.path) + async (file: TFile, name: string) => { + await this.renameFile(file, name, activeFile.path) }, () => { this.modals.splice(this.modals.indexOf(modal), 1)