Problems with undo on drag events



I’m trying to add undo/redo functionality to some mouse drag events. The problem I’m having is the undo action for the drag event seems to be disappearing from the undo stack. So, for example if I do the following:

  1. Make some edit in the application
  2. Do a mouse drag
  3. Hit Undo key command

What happens is the undo manager undoes the edit from step 1. Stepping through the code i can see the undo for the transaction in step 2 is never called. Here is what is happening in the code:

void mouseDown(const MouseEvent& e)

void mouseDrag(const MouseEvent& e)

void MyDataModel::updateFoo()
    myUndoableAction *ua = new myUndoableAction();

I’ve also tried structuring it the way described in this forum post:

but I still have the same problem. Does anyone have any advice or tips on how to get this working? Thanks in advance.[/url][/code]


That does sound like it should work, as far as I can see from your code snippet. Presumably it’ll work if you call beginNewTransaction after the drag ends, but I can’t think why it’d need that to work…


Thank you for the response. I had some more time to look into this and discovered the problem. There was a case in my
UndoableAction::perform() method where it would sometimes return false. In those cases the transaction would not persist in the undo history.