Skip to content

Commit 4695221

Browse files
committed
Changed overwrite confirmation to only appear on new notes
Overwrite confirmation should only appear if a new note is created, not when updating the metadata for an existing note.
1 parent 9a521a1 commit 4695221

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/main.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,15 @@ export default class MediaDbPlugin extends Plugin {
512512
// look if file already exists and ask if it should be overwritten
513513
const file = this.app.vault.getAbstractFileByPath(filePath);
514514
if (file) {
515-
const shouldOverwrite = await new Promise<boolean>(resolve => {
516-
new ConfirmOverwriteModal(this.app, fileName, resolve).open();
517-
});
515+
if (!options.isUpdating) {
516+
const shouldOverwrite = await new Promise<boolean>(resolve => {
517+
new ConfirmOverwriteModal(this.app, fileName, resolve).open();
518+
});
518519

519-
if (!shouldOverwrite) {
520-
throw new Error('MDB | file creation cancelled by user');
520+
if (!shouldOverwrite) {
521+
throw new Error('MDB | file creation cancelled by user');
522+
}
521523
}
522-
523524
await this.app.vault.delete(file);
524525
}
525526

@@ -574,9 +575,9 @@ export default class MediaDbPlugin extends Plugin {
574575
console.debug(`MDB | newMediaTypeModel after merge`, newMediaTypeModel);
575576

576577
if (onlyMetadata) {
577-
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachFile: activeFile, folder: activeFile.parent ?? undefined, openNote: true });
578+
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachFile: activeFile, folder: activeFile.parent ?? undefined, openNote: true, isUpdating: true });
578579
} else {
579-
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachTemplate: true, folder: activeFile.parent ?? undefined, openNote: true });
580+
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachTemplate: true, folder: activeFile.parent ?? undefined, openNote: true, isUpdating: true });
580581
}
581582
}
582583

src/utils/Utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export interface CreateNoteOptions {
193193
attachFile?: TFile;
194194
openNote?: boolean;
195195
folder?: TFolder;
196+
isUpdating?: boolean; // New property
196197
}
197198

198199
export function migrateObject<T extends object>(object: T, oldData: any, defaultData: T): void {

0 commit comments

Comments
 (0)