0

How can i set up a specific Redo action the same i setup Undo actions when using prepareWithInvocationTarget

using my approach, the redo doesn't work (undo works)

- (void)removeSmth:(Smth *)smth index:(NSInteger)indexOfSmth {

    [self.document.undoManager beginUndoGrouping];

    ...

    [self removeSmth:smth];
    [[self.document.undoManager prepareWithInvocationTarget:self] undoInsertSmth:smth index:indexOfSmth];

    ...

    [self.document.undoManager endUndoGrouping];

}

- (void)undoInsertSmth:(Smth *)smth index:(NSUInteger)index {

    [self insertSmth:smth index:index];

}
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179

1 Answers1

2

In the undo method, if called from undoing you should register a undo

- (void)removeSmth:(Smth *)smth index:(NSInteger)indexOfSmth {

    [self.document.undoManager beginUndoGrouping];

    ...

    [self removeSmth:smth];
    [[self.document.undoManager prepareWithInvocationTarget:self] undoInsertSmth:smth index:indexOfSmth];

    ...

    [self.document.undoManager endUndoGrouping];

}

- (void)undoInsertSmth:(Smth *)smth index:(NSUInteger)index {
    if ([self.document.undoManager isUndoing]) {
        [[self.document.undoManager prepareWithInvocationTarget:self] removeSmth:smth index:index];
    }
    [self insertSmth:smth index:index];

}
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179