Re: Adding to NSTextView's current undo group?

  • > Does anybody know if there is a way to add undo invocations to
    > NSTextView's undo stack without starting a new undo group?


    You made this post back on 2005, but it didn't get any responses. I
    have the same questions. I want make changes to a textStorage in an
    undo friendly way. Right now I'm using this pattern:

    if ([textView shouldChangeTextInRange:range
    replacementString:@"..."]) {
      [textStorage replaceCharactersInRange:range withString:@"..."];
      [textView didChangeText];

    It works, but it breaks undo coalescing, and I really want the text
    system to coalesce my changes when possible. I've found that I can
    replace the above with:

    [textView setSelectedRange:range]
    [textView insertText:@"..."]

    That seems to work, but the insertText: method says that it shouldn't
    be used except by input systems. So my question is what's the best
    way to programatically edit text, while getting edits coalesces. And
    if the answer is insertText: is there anything special that I need to
    do to make it work right all the time?

previous month september 2007 next month
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today