Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextView textStorage woes



Hi Folks.

I'm trying to create a "split" editor, much like xcode - where I have 2 NSTextViews with the same text that stay updated with each other.

I've looked thru the list, and it seems that the established way to do this is to do:

[[mirrorEditor layoutManager] replaceTextStorage:[mainEditor textStorage]];

(assuming "mirrorEditor" and "mainEditor" are NSTextViews).

This does indeed work, however I am noticing some weirdness with fonts:

If I start typing in my "main" textview, all is ok - I can then type in the "mirror" textview, and the font remains correct.

However, if I start typing in my "mirror" textview BEFORE I have typed anything in my "main" textview then the fonts are messed up (they default to the system font).

This can be demonstrated by a very small piece of code:

(assume you have hooked up an NSView in IB on your main window to hold the NSTextViews called "container")

---------------------------------------------------------

//create main textview
NSTextView *mainEditor = [[NSTextView alloc] initWithFrame:NSMakeRect (0,0,[mainView bounds].size.width, 100)];
//set some obviously large font
[mainEditor setFont:[NSFont fontWithName:@"Monaco" size:20.0]];


//create mirror textview above it
NSTextView *mirrorEditor = [[NSTextView alloc] initWithFrame:NSMakeRect(0,120,[mainView bounds].size.width, 100)];
//set some obviously large font
[mirrorEditor setFont:[NSFont fontWithName:@"Monaco" size:20.0]];


//sync mirror with main
[[mirrorEditor layoutManager] replaceTextStorage:[mainEditor textStorage]];


//add editors to view
[container addSubview:mainEditor];
[container addSubview:mirrorEditor];

---------------------------------------------------------

Can anyone explain what is going on, and how to solve?

Cheers,

Duncan.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.