diff --git a/src/lib/components/NoteEditor.svelte b/src/lib/components/NoteEditor.svelte index d5ffa5e..fb20161 100644 --- a/src/lib/components/NoteEditor.svelte +++ b/src/lib/components/NoteEditor.svelte @@ -134,6 +134,21 @@ bgStyle = `background-color: ${colors.bg}`; }); + // Track whether mousedown started on the overlay (not inside the editor). + // Prevents closing when the user selects text inside the editor and + // releases the mouse outside — the click event fires on the overlay, + // but we only want to close if the press also started there. + let mousedownOnOverlay = false; + + function handleOverlayMousedown(e: MouseEvent) { + mousedownOnOverlay = e.target === e.currentTarget; + } + + function handleOverlayClick() { + if (mousedownOnOverlay) saveAndClose(); + mousedownOnOverlay = false; + } + async function saveAndClose() { if (!title.trim() && !content.trim()) { onClose(); @@ -195,7 +210,8 @@