fix: comment deletion targets the clicked comment span, not cursor selection

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Etienne Delvarre
2026-05-29 15:31:45 +02:00
parent eebb9cfa69
commit dc81db3c2d
+18 -3
View File
@@ -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);
}