Skip to content

Commit

Permalink
await each renameFunc so that the deduplication mechanism could work
Browse files Browse the repository at this point in the history
  • Loading branch information
reorx committed May 8, 2022
1 parent 4886fce commit 9d3b311
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ interface RenameTask {
name: string
}

type renameFuncType = (file: TFile, name: string) => Promise<void>

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
Expand Down Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9d3b311

Please sign in to comment.