diff --git a/backend/utils.py b/backend/utils.py index 4e8e2b4..b1eaf39 100644 --- a/backend/utils.py +++ b/backend/utils.py @@ -86,6 +86,10 @@ def move_note(notes_dir: str, old_path: str, new_path: str) -> bool: if not old_full_path.exists(): return False + # Check if target already exists (prevent overwriting) + if new_full_path.exists(): + return False + # Invalidate cache for old path old_key = str(old_full_path) if old_key in _tag_cache: diff --git a/frontend/app.js b/frontend/app.js index 8a09198..531550a 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -2615,6 +2615,15 @@ function noteApp() { if (oldPath === newPath) return; + // Check if a note with the new name already exists + const existingNote = this.notes.find(n => n.path.toLowerCase() === newPath.toLowerCase()); + if (existingNote) { + alert(`A note named "${newName}" already exists in this folder.`); + // Reset the name in the UI + this.currentNoteName = oldPath.split('/').pop().replace('.md', ''); + return; + } + // Create new note with same content try { const response = await fetch(`/api/notes/${newPath}`, {