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); }