2 Replies Latest reply on Oct 23, 2011 3:03 PM by Loic.Aigon

    [JS] Check for undo/redo source contents

    Loic.Aigon Adobe Community Professional

      Hi all,


      I am a bit stuck so I come here in order to get your thoughts


      Ok, I am trying to get a correct monitoring of undo/redo calls so I can check the source and the target of the undo/redo. Let's imagine the following character :


      1. User types "A"

      2. User selects "A" and type in "B" instead.

      3. User undoes so "B" turns back to A"

      4. User finally redoes so "A" turns back to "B"


      There we could say that B is the source where A is the target. I need to check that when undoing B, it turns to a "A" and vice versa.

      Basically I got some success when user is in this immediate scenario, adding beforeInvoke/afterInvoke eventListeners to the undo/redo menu actions.

      So when user undoes/redoes I can read the character before it's replaced and after it's replaced and see it is what I am looking at.


      The true problem comes when user undoes/redoes several times in a row. In this case, the beforeInvoke may catch a "C" character as source and not "B". This is because I am trying to compare two contents which may not be related to the same selection. So for example my comparison gives me A/A when indeed I have a B/A to consider.


      So I come to the conclusion that beforeInvoke/afterInvoke isn't really reliable as a process. I have then looked at some "memory" property in the application that could have stored the character to be placed when undoing/redoing but fails. I tried the Event.AFTER_SELECTION_CHANGED eventListener but I have no way to reach the source contents before it was replaced.


      Any idea ?