• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: insertText
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: insertText


  • Subject: Re: insertText
  • From: Douglas Davidson <email@hidden>
  • Date: Wed, 4 Jan 2006 11:41:45 -0800


On Jan 4, 2006, at 3:35 AM, Philip Dow wrote:

It may also be necessary to surround that replaceCharactersInRange:withString: method with

[[textView textStorage] beginEditing];
[[textView textStorage] endEditing];

Those should ensure a clean attributed string, whatever your changes may be. If the NSTextView instance is editable, you should also call

[textView shouldChangeTextInRange:[textView rangeForUserTextChange] replacementString:someString]

and proceed only if that method returns true. As far as I can tell, that method also ensures that your changes are registered with the undo mechanism, although I'm not sure if does more or less.

The beginEditing/endEditing calls aren't strictly necessary; they are a performance improvement, to make sure that the layout managers are notified only at the end of a series of modifications, rather than for each one. If you're only making one modification to the attributed string, you can omit them, although I think it's good practice to use them in this sort of scenario--then if the code in future is modified to make multiple calls modifying the attributed string, they'll be there already.


You are correct to say that shouldChangeTextInRange:replacementString: ensures that your changes are registered with the undo manager; it also causes delegate messages and notifications to be sent out, and handles clearing of any unfinished input method state. You should also call didChangeText after the change has taken place. If your changes affect discontiguous ranges rather than a single range, you may use shouldChangeTextInRanges:replacementStrings:. In general, all changes to the text that take place as a result of user actions, or are intended to be equivalent to and undoable with user actions, should be wrapped in should-change/did-change calls. Purely programmatic changes, not intended to be undoable by the user, should not. Changes to a non-editable text view would fall in the latter category.

Douglas Davidson

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >RE: insertText (From: "Kenny Millar" <email@hidden>)
 >Re: insertText (From: Andreas Mayer <email@hidden>)
 >Re: insertText (From: Philip Dow <email@hidden>)

  • Prev by Date: Re: perform ... afterDelay?
  • Next by Date: MainMenu
  • Previous by thread: Re: insertText
  • Next by thread: Re: insertText
  • Index(es):
    • Date
    • Thread