OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
641 stars 92 forks source link

Word DocumentSelectionChanged event not firing when selecting a comment in a Word document by clicking on the comment in the interface #4394

Open iShtopoR opened 3 weeks ago

iShtopoR commented 3 weeks ago

Version: Word Online.

I'm facing is that I'm using

Office.context.document.addHandlerAsync(Office.EventType.DocumentSelectionChanged, (event: any) => { 
    console.log("event", event);
}); 

to track changes in the getSelection method in a Word document within my Add-in plugin. I aim to retrieve the content of a comment. However, when selecting a comment through the interface, the selection doesn't change, thus preventing me from accessing the comment's content.

const comments = context.document.getSelection().getComments();
comments.load("items");
await context.sync();
comments.items.forEach((comment: Word.Comment) => {
    console.log("Comment: ", comment.content);
});

image