Skip to content

Commit 4f283b6

Browse files
committed
fix: imported comments scroll to the bottom
1 parent b5cfdfe commit 4f283b6

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

packages/super-editor/src/extensions/comment/comments-plugin.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ export const CommentsPlugin = Extension.create({
321321
currentBounds,
322322
node,
323323
});
324+
// Add decoration for tracked changes
325+
const isActiveTrackedChange = currentActiveThreadId === id;
326+
if (isActiveTrackedChange) {
327+
const trackedChangeDeco = Decoration.inline(pos, pos + node.nodeSize, {
328+
style: `border-width: 2px;`,
329+
'data-thread-id': id,
330+
class: 'sd-editor-tracked-change-highlight',
331+
});
332+
333+
decorations.push(trackedChangeDeco);
334+
}
324335
}
325336
});
326337

packages/superdoc/src/components/CommentsLayer/CommentDialog.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ const setFocus = () => {
117117
activeComment.value = props.comment.commentId;
118118
props.comment.setActive(proxy.$superdoc);
119119
if (editor?.commands?.setCursorById) {
120-
editor.commands.setCursorById(activeComment.value);
120+
const cursorId = props.comment.importedId || props.comment.commentId;
121+
editor.commands.setCursorById(cursorId);
121122
}
122123
};
123124

packages/superdoc/src/components/CommentsLayer/CommentsLayer.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ const getCurrentComments = computed(() => {
101101
102102
watch(activeComment, (newVal) => {
103103
if (!newVal) return;
104-
const element = document.getElementById(newVal);
105-
element?.scrollIntoView({ behavior: 'smooth', block: 'center' });
104+
const element = document.querySelector(`[data-id="${newVal}"]`);
105+
if (element) {
106+
element?.scrollIntoView({ behavior: 'smooth', block: 'center' });
107+
}
106108
});
107109
108110
defineExpose({

packages/superdoc/src/components/CommentsLayer/FloatingComments.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ const handleDialog = (dialog) => {
6565
const editorBounds = props.parent.getBoundingClientRect();
6666
6767
const comment = getFloatingComments.value.find((c) => c.commentId === id || c.importedId == id);
68-
let position = editorCommentPositions.value[id]?.bounds || {};
68+
const positionKey = id || comment?.importedId;
69+
let position = editorCommentPositions.value[positionKey]?.bounds || {};
6970
7071
// If this is a PDF, set the position based on selection bounds
7172
if (props.currentDocument.type === 'application/pdf') {
@@ -127,8 +128,8 @@ watch(activeComment, (newVal, oldVal) => {
127128
128129
const comment = commentsStore.getComment(activeComment.value);
129130
if (!comment) return (verticalOffset.value = 0);
130-
131-
const renderedItem = renderedSizes.value.find((item) => item.id === comment.commentId);
131+
const commentKey = comment.commentId || comment.importedId;
132+
const renderedItem = renderedSizes.value.find((item) => item.id === commentKey);
132133
if (!renderedItem) return (verticalOffset.value = 0);
133134
134135
const selectionTop = comment.selection.selectionBounds.top;

packages/superdoc/src/stores/comments-store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ export const useCommentsStore = defineStore('comments', () => {
584584
const keys = Object.keys(editorCommentPositions.value);
585585
const isPdfComment = c.selection?.source !== 'super-editor';
586586
if (isPdfComment) return true;
587-
return keys.includes(c.commentId);
587+
const commentKey = c.commentId || c.importedId;
588+
return keys.includes(commentKey);
588589
});
589590
return comments;
590591
});

0 commit comments

Comments
 (0)