From 8d5f27cd1239b4633da3872501fd919359972baf Mon Sep 17 00:00:00 2001 From: Frederic Cabassut Date: Tue, 10 Mar 2026 10:16:42 +0100 Subject: [PATCH] fix: prevent note editor from closing when text selection ends outside overlay Track mousedown origin so click-outside-to-close only fires when both mousedown and mouseup occur on the overlay backdrop, not when dragging a text selection from inside the editor. Co-Authored-By: Claude Opus 4.6 --- src/lib/components/NoteEditor.svelte | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 @@