@@ -3,7 +3,7 @@ import { ref, reactive, computed } from 'vue';
33import { comments_module_events } from '@harbour-enterprises/common' ;
44import { useSuperdocStore } from '@superdoc/stores/superdoc-store' ;
55import { syncCommentsToClients } from '../core/collaboration/helpers.js' ;
6- import { Editor , } from '@harbour-enterprises/super-editor' ;
6+ import { Editor , trackChangesHelpers , TrackChangesBasePluginKey , CommentsPluginKey } from '@harbour-enterprises/super-editor' ;
77import { getRichTextExtensions } from '@harbour-enterprises/super-editor' ;
88import useComment from '@superdoc/components/CommentsLayer/use-comment' ;
99
@@ -441,7 +441,7 @@ export const useCommentsStore = defineStore('comments', () => {
441441 * @param {String } param0.documentId The document ID
442442 * @returns {void }
443443 */
444- const processLoadedDocxComments = async ( { superdoc, comments, documentId } ) => {
444+ const processLoadedDocxComments = async ( { superdoc, editor , comments, documentId } ) => {
445445 const document = superdocStore . getDocument ( documentId ) ;
446446
447447 if ( __IS_DEBUG__ ) console . debug ( '[processLoadedDocxComments] processing comments...' , comments ) ;
@@ -478,6 +478,34 @@ export const useCommentsStore = defineStore('comments', () => {
478478
479479 addComment ( { superdoc, comment : newComment } ) ;
480480 } ) ;
481+
482+ const trackedChanges = trackChangesHelpers . getTrackChanges ( editor . state ) ;
483+
484+ // Create comments for tracked changes
485+ // that do not have a corresponding comment (created in Word).
486+ trackedChanges . forEach ( ( { mark } ) => {
487+ const foundComment = commentsList . value . find ( ( i ) => i . commentId === mark . attrs . id ) ;
488+
489+ if ( foundComment ) {
490+ return ;
491+ }
492+
493+ const { dispatch } = editor . view ;
494+ const { tr } = editor . view . state ;
495+
496+ const markMetaKeys = {
497+ trackInsert : 'insertedMark' ,
498+ trackDelete : 'deletionMark' ,
499+ trackFormat : 'formatMark' ,
500+ } ;
501+
502+ const markKeyName = markMetaKeys [ mark . type . name ] ;
503+ if ( markKeyName ) {
504+ tr . setMeta ( CommentsPluginKey , { type : 'force' } ) ;
505+ tr . setMeta ( TrackChangesBasePluginKey , { [ markKeyName ] : mark } ) ;
506+ dispatch ( tr ) ;
507+ }
508+ } ) ;
481509 }
482510
483511 const translateCommentsForExport = ( ) => {
0 commit comments