• 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: Strange behaviour of text insertion in NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Strange behaviour of text insertion in NSTextView


  • Subject: Re: Strange behaviour of text insertion in NSTextView
  • From: Ali Ozer <email@hidden>
  • Date: Tue, 20 Apr 2004 11:04:54 -0700

The strange behaviour is this: when the source file at fromPath is in MS Word doc format, the insertion dirties the document and can be undone, but when the source is rtf or rtfd, it slips past the text view's undo manager completely unobserved. The document stays clean, and the insertion can't be undone. Has anyone else come across this behaviour, and can anyone explain it?

I don't have an explanation offhand, but I can tell you that insertText: is intended as the funnel point for user typing, and its behavior is not likely to be appropriate for any other use.


Yes, I know I was being a bit naughty here. This was one of a sequence of approaches, in which I thought I'd give insertText: a try to see what happened. I was intrigued by this anomaly. I've since replaced it with insertAttributedString: applied to the textStorage. Trouble is, this method *never* dirties the document...

If you want to work directly with the text storage, and you want to have your changes treated as user changes (that is, marked undoable, cause the document to appear dirty, etc), you need to go through the following NSTextView methods around the changes:

- (BOOL)shouldChangeTextInRange:(NSRange)affectedCharRange replacementString:(NSString *)replacementString;
- (void)didChangeText;

for instance:

if ([textView shouldChangeTextInRange:replaceRange replacementString:[temp string]]) {
[[textView textStorage] replaceCharactersInRange:replaceRange withAttributedString:temp];
[textView didChangeText];
}

Ali
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Strange behaviour of text insertion in NSTextView
      • From: Jeremy Dronfield <email@hidden>
    • Re: Strange behaviour of text insertion in NSTextView
      • From: Jeremy Dronfield <email@hidden>
References: 
 >Strange behaviour of text insertion in NSTextView (From: Jeremy Dronfield <email@hidden>)
 >Re: Strange behaviour of text insertion in NSTextView (From: Douglas Davidson <email@hidden>)
 >Re: Strange behaviour of text insertion in NSTextView (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: Re: [little OT] Licensing/Implementing in Cocoa/Obj-C
  • Next by Date: Re: Monitoring a folder?
  • Previous by thread: Re: Strange behaviour of text insertion in NSTextView
  • Next by thread: Re: Strange behaviour of text insertion in NSTextView
  • Index(es):
    • Date
    • Thread