Well, I was going to argue with you, but your post triggered further
investigation.  I realized that in the past, I had constructed my own.
Somehow, in this case, I got it in my head that the bindings would make the
text view use my NSTextStorage.  Duh.  So I changed to the following in the
test app:

@interface MyDocument : NSDocument
{
    IBOutlet NSTextView* tv;
    NSAttributedString* ts;
}
@property(copy) NSAttributedString* ts;
- (IBAction)insertSomething:(id)sender;
@end

- (IBAction)insertSomething:(id)sender {
    NSUInteger index = [tv selectedRange].location;
    NSTextStorage* vtc = [tv textStorage];
    [vtc beginEditing];
    [vtc insertAttributedString:[[NSAttributedString alloc]
initWithString:@"XYZ"] atIndex:index];
    [vtc endEditing];
}

At least now, I'm dinging the right text storage and the insertion works.
However, it does confirm my original problem, i.e., that the programmatic
edit does not show up in the bound NSAttributedString unless there is an
additional text-entry edit.  Now I'm thinking bug report, unless there is
something else I can do to trigger the KVO for programmatic edits.

I suppose a workaround could be to set up a dummy ivar and a dependency to
make it update.

On 2/21/10 7:24 PM, "Kyle Sluder" <kyle.slu...@gmail.com> wrote:

> On Sun, Feb 21, 2010 at 2:00 PM, Gordon Apple <g...@ed4u.com> wrote:
>> This is getting stranger by the minute.  I ruled out the menu issue as the
>> cause, then created a test app from the standard doc template.  Window
>> contain a scrolling text view and a button.  The app edits and archives
>> correctly (compiled using GC).  "init" sets an initial string in ts.  The
>> text view is bound to ts.
> 
> You need to post the code that sets up the text system. Unless you
> actually meant "bound" in the sense of Cocoa Bindings, in which case
> none of this is ever going to work because then the text view will
> operate on a copy of the text storage you've provided. The only way to
> get the text view to use your text storage is to set it up yourself.
> 
> --Kyle Sluder



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to