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:
+18
-3
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user