• 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: Philip Dow <email@hidden>
  • Date: Wed, 4 Jan 2006 12:35:14 +0100

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.

-Phil


On Jan 4, 2006, at 12:05 PM, Andreas Mayer wrote:


Am 04.01.2006 um 10:15 Uhr schrieb Kenny Millar:

Do I use [textView string], to get the existing contents, manipulate them
manually and then [textView setString] to send them back, or is there a more
elegant method?

Yes, there is.

[textView textStorage] returns an NSTextStorage which is a subclass of NSMutableAttributedString.

So you can do:

[[textView textStorage] replaceCharactersInRange:range withString:string];


Andreas _______________________________________________ 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


_______________________________________________ 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
  • Follow-Ups:
    • Re: insertText
      • From: Douglas Davidson <email@hidden>
References: 
 >RE: insertText (From: "Kenny Millar" <email@hidden>)
 >Re: insertText (From: Andreas Mayer <email@hidden>)

  • Prev by Date: Re: How to execute the .app from the Terminal window
  • Next by Date: UNICODE from a WinTel box
  • Previous by thread: Re: insertText
  • Next by thread: Re: insertText
  • Index(es):
    • Date
    • Thread