This commit is contained in:
Gamosoft 2025-12-19 15:52:29 +01:00
parent b69432610b
commit 088363d548
1 changed files with 49 additions and 56 deletions

View File

@ -2248,22 +2248,9 @@ function noteApp() {
setTimeout(() => this.scrollToAnchor(anchor), 100); setTimeout(() => this.scrollToAnchor(anchor), 100);
} }
}); });
} else { } else if (confirm(this.t('notes.create_from_link', { path: notePath }))) {
// Note doesn't exist - offer to create it // Note doesn't exist - create it (reuses createNote with duplicate check)
if (confirm(this.t('notes.create_from_link', { path: notePath }))) { this.createNote(null, notePath);
const newPath = notePath.endsWith('.md') ? notePath : `${notePath}.md`;
fetch(`/api/notes/${newPath}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ content: '' })
}).then(response => {
if (response.ok) {
const folderPath = newPath.includes('/') ? newPath.substring(0, newPath.lastIndexOf('/')) : '';
if (folderPath) this.expandedFolders.add(folderPath);
this.loadNotes().then(() => this.loadNote(newPath));
}
});
}
} }
}, },
@ -2839,7 +2826,13 @@ function noteApp() {
// UNIFIED CREATION FUNCTIONS (reusable from anywhere) // UNIFIED CREATION FUNCTIONS (reusable from anywhere)
// ===================================================== // =====================================================
async createNote(folderPath = null) { async createNote(folderPath = null, directPath = null) {
let notePath;
if (directPath) {
// Direct path provided (e.g., from wiki link) - skip prompting
notePath = directPath.endsWith('.md') ? directPath : `${directPath}.md`;
} else {
// Use provided folder path, or dropdown target folder context, or homepage folder // Use provided folder path, or dropdown target folder context, or homepage folder
// Note: Check dropdownTargetFolder !== null to distinguish between '' (root) and not set // Note: Check dropdownTargetFolder !== null to distinguish between '' (root) and not set
let targetFolder; let targetFolder;
@ -2871,17 +2864,17 @@ function noteApp() {
const validatedName = validation.sanitized; const validatedName = validation.sanitized;
let notePath;
if (targetFolder) { if (targetFolder) {
notePath = `${targetFolder}/${validatedName}.md`; notePath = `${targetFolder}/${validatedName}.md`;
} else { } else {
notePath = validatedName.endsWith('.md') ? validatedName : `${validatedName}.md`; notePath = validatedName.endsWith('.md') ? validatedName : `${validatedName}.md`;
} }
}
// CRITICAL: Check if note already exists // CRITICAL: Check if note already exists (applies to both prompt and direct path)
const existingNote = this.notes.find(note => note.path === notePath); const existingNote = this.notes.find(note => note.path === notePath);
if (existingNote) { if (existingNote) {
alert(this.t('notes.already_exists', { name: validatedName })); alert(this.t('notes.already_exists', { name: notePath }));
return; return;
} }
@ -2893,9 +2886,9 @@ function noteApp() {
}); });
if (response.ok) { if (response.ok) {
if (targetFolder) { // Expand parent folder if note is in a subfolder
this.expandedFolders.add(targetFolder); const folderPart = notePath.includes('/') ? notePath.substring(0, notePath.lastIndexOf('/')) : '';
} if (folderPart) this.expandedFolders.add(folderPart);
await this.loadNotes(); await this.loadNotes();
await this.loadNote(notePath); await this.loadNote(notePath);
} else { } else {