Implement some kind of UndoRecord class in office-js for Office Word

Implement some kind of UndoRecord class in office-js for Office Word
16

Upvotes

Upvote

 May 19 2021
4 Comments (4 New)
New

I have a Word add-in that needs to do some manipulation on the document and be able to undo them with one click on the undo button. In the VSTO add-in version, I am using the UndoRecord class, but it looks like there are no analogues in office-js.

Comments
Brass Contributor

@lindalu-MSFT 
This would be a great extension

Microsoft

@asokolov Thanks for posting. Can you explain more about this requirement? Are you saying that you want to undo and rollback to a specific document history?

 

Thanks.

Brass Contributor

Hello Yun,

maybe I can jump in here. We also use the UndoRecord class in our VSTO Add-In - quite a lot actually. There are two main things we achived with that:

  1. Group several manipulations in the COM object model to a single undo line, to prevent the user to go to an intermediate state halfway through that is not valid (e.g. content control is inserted but properties and tag metadata is not set yet)
    As I understood our previous Teams conversation this can be achieved differently in JS API because all manipulations in a single Word.run are part of one undo record anyway
    The question is now, if there is or should be a possibility to specify a name this undo entry - I think it should
  2. We also used UndoRecords for performance optimizations (really!)
    We did a log of changes on content controls in large documents, and if every single change of a title, color or appearance is a separate undo step, then this got very slow. By using an UndoRecord we stopped Word storing a restorable version of the document after every step of the process, which made it extremely slow.
    I hope that is not really necessary in JS API ;)

That's what we did with it, does this help you?

Ernst 

Brass Contributor

Hi, @Yun_Wang. Thanks for the answer!

In my case, I need an API that will allow me to put multiple commands in a batch, and if the user decides to undo the action they took, all the commands in the batch will be undone (by pressing Ctrl+z or Undo just once).

 

My specific use case: I have an add-in that does some rendering on a document (by changing a few content controls) and after rendering is complete, it also updates some document props. I can't do it within a single context.sync call and sometimes even within a single Word.run call due to business logic.

And once that is complete, the user will only be able to undo it by pressing Word's undo button (or Ctrl+z) multiple times. So I want to fix this so that the user can do the undo operation once.

 

In VSTO version I'm using the UndoRecord class to achieve this. So I'm looking for something similar in the OfficeJS API.

 

Regards,

Alex.