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() {
|
function deleteComment() {
|
||||||
if (!tiptapEditor || !activeCommentMark) return;
|
if (!tiptapEditor || !activeCommentMark) return;
|
||||||
// Find the position of this mark in the editor and remove it
|
// Find the position of this comment span in the document
|
||||||
tiptapEditor.chain().focus().unsetMark('comment').run();
|
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();
|
closeCommentPopup();
|
||||||
// Trigger save
|
|
||||||
clearTimeout(saveTimeout);
|
clearTimeout(saveTimeout);
|
||||||
saveTimeout = setTimeout(saveContent, 500);
|
saveTimeout = setTimeout(saveContent, 500);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user