I have a fairly complicated NSTextView subclass in one of my projects. I'm currently working on getting find/replace to work with an inline find bar (e.g. Safari, Xcode) and want to properly support undo/redo for the replace operations.
I want the Replace All command to support undo as a single command (i.e. if there are 8 replacements to be made in the text view, it should also undo those 8 replacements at once).
I'm wondering if there is a counterpart to shouldChangeTextInRanges:replaceStrings:
that I can call after checking to do the replacement. I expected there would be a replaceCharactersInRanges:withStrings:
or something similar, but there doesn't seem to be.
The only way I can think to do this at the moment is to check with a call to shouldChangeTextInRanges:replaceStrings:
first, then call replaceCharactersInRange:withString:
with the entire range of the text view and the new string (with the replacements made) as the second argument.
This just seems unnecessary, I don't really want to replace the entire string if I don't have to. Any ideas?