2
votes

I am working on word addin using office js I have a requirement to detect whether user has entered and moved out of a table during review. I have created the table under a content control. What I need to implement if I click/put cursor using key at any column of table then a global variable value will change to true and when cursor moves outside that table then the variable changes to false and I shall assume user has done some change in table(even if they actually haven't) and I shall save the whole document.

Using below method I am able to detect generic cursor movement event.

        Office.context.document.addHandlerAsync("documentSelectionChanged", mySelectionHandler,
            function (result) {
                //write(result.value)
            }
        );

However, I couldn't find any mechanism to assert my cursor is within a table or outside that table. Could you help on this?

1

1 Answers

0
votes

You could try using getSelection to get the Range object where the cursor currently is. Then call the Range object's parentTableOrNullObject or parentContentControlOrNullObject properties to determine if the cursor is in a table/content control. Then use the id or title properties to identify the table the cursor is in.