diff --git a/modules/ui/obsidian-notes-editor.js b/modules/ui/obsidian-notes-editor.js index 86a28946..81878548 100644 --- a/modules/ui/obsidian-notes-editor.js +++ b/modules/ui/obsidian-notes-editor.js @@ -28,7 +28,9 @@ async function findOrCreateNote(elementId, elementType, coordinates) { if (note) { INFO && console.log("Found note by FMG ID:", note.path); - return note; + closeDialogs("#obsidianNoteLoading"); + // Show dialog with option to open linked note or choose different one + return await showLinkedNoteDialog(note, elementId, elementType, coordinates); } // Find by coordinates @@ -57,6 +59,46 @@ async function findOrCreateNote(elementId, elementType, coordinates) { return await showNoteSelectionDialog(matches, elementId, elementType, coordinates); } +async function showLinkedNoteDialog(note, elementId, elementType, coordinates) { + return new Promise((resolve, reject) => { + alertMessage.innerHTML = ` +
+

✓ Found linked note:

+
+
${note.name}
+
Path: ${note.path}
+
+

This element is already linked to the note above. You can open it or choose a different note.

+
+ `; + + $("#alert").dialog({ + title: "Linked Note Found", + width: "500px", + buttons: { + "Open Linked Note": function () { + $(this).dialog("close"); + resolve(note); + }, + "Choose Different Note": async function () { + $(this).dialog("close"); + try { + const differentNote = await promptCreateNewNote(elementId, elementType, coordinates); + resolve(differentNote); + } catch (error) { + reject(error); + } + }, + Cancel: function () { + $(this).dialog("close"); + reject(new Error("Cancelled")); + } + }, + position: {my: "center", at: "center", of: "svg"} + }); + }); +} + function showLoadingDialog() { alertMessage.innerHTML = `