mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
feat(obsidian): add option to choose different note even when linked
Problem: When clicking on a burg/marker that already has a linked note, it would automatically open that note without giving the user any choice. Users need the ability to manually browse/search for a different note. Solution: Show a dialog when a linked note is found with 3 options: 1. "Open Linked Note" - Open the currently linked note (default/fast path) 2. "Choose Different Note" - Browse/search for a different note to link 3. "Cancel" - Close the dialog Benefits: - Gives users full control over note selection - Still makes the common case (opening linked note) fast and easy - Allows re-linking burgs/markers to different notes - Shows the path of the linked note before opening This addresses the need to manually browse even when a note is already linked, while preserving the fast instant-open behavior for linked notes.
This commit is contained in:
parent
f575631e30
commit
d58dc10b55
1 changed files with 43 additions and 1 deletions
|
|
@ -28,7 +28,9 @@ async function findOrCreateNote(elementId, elementType, coordinates) {
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
INFO && console.log("Found note by FMG ID:", note.path);
|
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
|
// Find by coordinates
|
||||||
|
|
@ -57,6 +59,46 @@ async function findOrCreateNote(elementId, elementType, coordinates) {
|
||||||
return await showNoteSelectionDialog(matches, elementId, elementType, coordinates);
|
return await showNoteSelectionDialog(matches, elementId, elementType, coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function showLinkedNoteDialog(note, elementId, elementType, coordinates) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
alertMessage.innerHTML = `
|
||||||
|
<div style="padding: 1em;">
|
||||||
|
<p style="margin-bottom: 1em;"><strong>✓ Found linked note:</strong></p>
|
||||||
|
<div style="padding: 12px; background: #f0f8ff; border: 1px solid #0066cc; border-radius: 4px; margin-bottom: 1.5em;">
|
||||||
|
<div style="font-weight: bold; margin-bottom: 4px;">${note.name}</div>
|
||||||
|
<div style="font-size: 0.9em; color: #666;">Path: ${note.path}</div>
|
||||||
|
</div>
|
||||||
|
<p style="font-size: 0.9em; color: #666;">This element is already linked to the note above. You can open it or choose a different note.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
$("#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() {
|
function showLoadingDialog() {
|
||||||
alertMessage.innerHTML = `
|
alertMessage.innerHTML = `
|
||||||
<div style="text-align: center; padding: 2em;">
|
<div style="text-align: center; padding: 2em;">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue