From 2d1cc4baf0e08417587d4b46fb7d500d5a92d2ab Mon Sep 17 00:00:00 2001 From: drelich Date: Tue, 17 Mar 2026 09:27:46 +0100 Subject: [PATCH] Add Discard Changes button to revert unsaved edits - Added handleDiscard function to reload original note content - New discard button appears next to save button when there are unsaved changes - Button uses X icon and gray styling to distinguish from save - Clicking discard reloads the original note title and content - Resets hasUnsavedChanges to false, allowing note switching again - Provides way to abandon changes without saving --- src/components/NoteEditor.tsx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/components/NoteEditor.tsx b/src/components/NoteEditor.tsx index e84c067..a32aab9 100644 --- a/src/components/NoteEditor.tsx +++ b/src/components/NoteEditor.tsx @@ -120,6 +120,22 @@ export function NoteEditor({ note, onUpdateNote, fontSize, onUnsavedChanges }: N setHasUnsavedChanges(true); }; + const handleDiscard = () => { + if (!note || !editor) return; + + // Reload original note content + setLocalTitle(note.title); + setLocalFavorite(note.favorite); + setHasUnsavedChanges(false); + + const firstLine = note.content.split('\n')[0].replace(/^#+\s*/, '').trim(); + const titleMatchesFirstLine = note.title === firstLine || note.title === firstLine.substring(0, 50); + setTitleManuallyEdited(!titleMatchesFirstLine); + + const html = marked.parse(note.content || '', { async: false }) as string; + editor.commands.setContent(html); + }; + const handleFavoriteToggle = () => { setLocalFavorite(!localFavorite); if (note) { @@ -184,6 +200,21 @@ export function NoteEditor({ note, onUpdateNote, fontSize, onUnsavedChanges }: N + +