• 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: Jeremy Dronfield <email@hidden>
  • Date: Tue, 20 Apr 2004 20:46:16 +0100

Well, here's a strange thing. After I actually implemented these methods, guess what? I got that peculiar covert infiltration behaviour again. Using the methods as prescribed:

fileText = [[NSAttributedString alloc] initWithPath:fromPath documentAttributes:NULL];

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

Exactly as originally reported, if fromPath is a Word doc, -textDidChange: is called, the document dirties, and the insertion is undoable. If the file is rtf or rtfd... nothing. The text goes into the text view all right, but no -textDidChange, no undo, no dirtiness. So, is this a bug associated with -initWithPath:? (Incidentally, it seems to make no difference whether documentAttributes is a dictionary pointer or NULL.)

Scratching my head over this one,

Jeremy



On 20 Apr 2004, at 7:04 pm, Ali Ozer wrote:

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.


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>)
 >Re: Strange behaviour of text insertion in NSTextView (From: Ali Ozer <email@hidden>)

  • Prev by Date: Re: Application icon
  • Next by Date: Re: [Q] Why unsolicited dealloc in NSKeyedUnarchiver?
  • Previous by thread: Re: Strange behaviour of text insertion in NSTextView
  • Next by thread: Outlined strokes and transparency WAS: Getting PDF and/or EPS data
  • Index(es):
    • Date
    • Thread