@@ -166,12 +166,16 @@ export const CommentsPlugin = Extension.create({
166166 } ;
167167
168168 // Generate decorations for comment highlights
169- const { decorations, allCommentIds } = processDocumentComments ( editor , doc , activeThreadId , oldState ) || { } ;
169+ const {
170+ decorations,
171+ allCommentIds,
172+ allCommentPositions
173+ } = processDocumentComments ( editor , doc , activeThreadId , oldState ) || { } ;
170174 const decorationSet = DecorationSet . create ( doc , decorations ) ;
171175
172176 // Emit the comment-positions event which signals that comments might have changed
173177 // SuperDoc will use this to update floating comments as necessary
174- editor . emit ( 'comment-positions' , allCommentIds ) ;
178+ editor . emit ( 'comment-positions' , { allCommentIds, allCommentPositions } ) ;
175179
176180 hasInitialized = true ;
177181 return {
@@ -225,6 +229,8 @@ const handleTrackedChangeTransaction = (trackedChangeMeta, trackedChanges, newEd
225229 } ;
226230 } ) ;
227231 }
232+
233+ const coords = editor . view . coordsAtPos ( step . to ) ;
228234 const emitParams = createOrUpdateTrackedChangeComment ( {
229235 documentId : editor . options . documentId ,
230236 event : isNewChange ? 'add' : 'update' ,
@@ -236,6 +242,7 @@ const handleTrackedChangeTransaction = (trackedChangeMeta, trackedChanges, newEd
236242 deletionNodes,
237243 nodes : nodes ,
238244 newEditorState,
245+ coords,
239246 } ) ;
240247
241248 if ( emitParams ) editor . emit ( 'commentsUpdate' , emitParams ) ;
@@ -258,7 +265,15 @@ const getTrackedChangeText = ({ node, mark, trackedChangeType, isDeletionInserti
258265 }
259266} ;
260267
261- const createOrUpdateTrackedChangeComment = ( { event, marks, deletionNodes, nodes, newEditorState, documentId } ) => {
268+ const createOrUpdateTrackedChangeComment = ( {
269+ event,
270+ marks,
271+ deletionNodes,
272+ nodes,
273+ newEditorState,
274+ documentId,
275+ coords,
276+ } ) => {
262277 const trackedMark = marks . insertedMark || marks . deletionMark || marks . formatMark ;
263278 const { type, attrs } = trackedMark ;
264279
@@ -306,6 +321,7 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
306321 author,
307322 authorEmail,
308323 date,
324+ coords,
309325 } ;
310326
311327 if ( event === 'add' ) params . event = comments_module_events . ADD ;
@@ -357,6 +373,8 @@ const trackCommentNodes = ({
357373 const threadId = attrs . commentId || attrs . importedId ;
358374 const isInternal = attrs . internal ;
359375 const color = getHighlightColor ( { activeThreadId, threadId, isInternal, editor } ) ;
376+
377+ const bounds = editor . view . coordsAtPos ( pos ) ;
360378 const deco = Decoration . inline (
361379 pos ,
362380 pos + node . nodeSize ,
@@ -375,8 +393,23 @@ const trackCommentNodes = ({
375393 start : pos ,
376394 end : pos + node . nodeSize ,
377395 internal : isInternal ,
396+ bounds,
378397 } ;
379398 } ) ;
399+
400+ const trackedChangeNode = getTrackedChangeNode ( node ) ;
401+ if ( trackedChangeNode ) {
402+ const threadId = trackedChangeNode . attrs . id ;
403+ const bounds = editor . view . coordsAtPos ( pos ) ;
404+
405+ allCommentPositions [ threadId ] = {
406+ threadId,
407+ start : pos ,
408+ end : pos + node . nodeSize ,
409+ internal : false ,
410+ bounds,
411+ } ;
412+ }
380413} ;
381414
382415/**
@@ -421,6 +454,7 @@ const processDocumentComments = (editor, doc, activeThreadId, pluginState) => {
421454 return {
422455 decorations,
423456 allCommentIds,
457+ allCommentPositions,
424458 } ;
425459} ;
426460
0 commit comments