Search code examples
iphoneiosuitextviewnsundomanager

UITextView undo position


I make a few changes to the begin, middle and end in a UITextView. Then I perform a step by step undoing by:

[self.textView.undoManager undo]

I'd like to programmatically scroll the UITextView to each corresponding undo position, after each undo.

How can I retrieve the last/upcoming undo position?


Solution

  • You cannot retrieve the last undo position from the text view, that's a private implementation detail.

    However, the text view should automatically position the caret after each undo step to where the undo happened, so you could probably just use [textView scrollRangeToVisible:textView.selectedRange] to go there.