From dc81db3c2d7834bca96f4a8fb98e0be2d13c04d5 Mon Sep 17 00:00:00 2001 From: Etienne Delvarre Date: Fri, 29 May 2026 15:31:45 +0200 Subject: [PATCH] fix: comment deletion targets the clicked comment span, not cursor selection Co-Authored-By: Claude Opus 4.6 --- public/index.html | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/public/index.html b/public/index.html index b5a7975..c2cd250 100644 --- a/public/index.html +++ b/public/index.html @@ -1844,10 +1844,25 @@ function closeCommentPopup() { function deleteComment() { if (!tiptapEditor || !activeCommentMark) return; - // Find the position of this mark in the editor and remove it - tiptapEditor.chain().focus().unsetMark('comment').run(); + // Find the position of this comment span in the document + const commentText = activeCommentMark.getAttribute('data-comment'); + const commentDate = activeCommentMark.getAttribute('data-date'); + const doc = tiptapEditor.state.doc; + let markFrom = null, markTo = null; + doc.descendants((node, pos) => { + if (markFrom !== null) return false; + if (node.isText) { + const mark = node.marks.find(m => m.type.name === 'comment' && m.attrs.text === commentText && m.attrs.date === commentDate); + if (mark) { + markFrom = pos; + markTo = pos + node.nodeSize; + } + } + }); + if (markFrom !== null) { + tiptapEditor.chain().focus().setTextSelection({ from: markFrom, to: markTo }).unsetMark('comment').run(); + } closeCommentPopup(); - // Trigger save clearTimeout(saveTimeout); saveTimeout = setTimeout(saveContent, 500); }