RE: NSTextView textStorage woes
RE: NSTextView textStorage woes
- Subject: RE: NSTextView textStorage woes
- From: Keith Blount <email@hidden>
- Date: Fri, 12 Aug 2005 06:29:37 -0700 (PDT)
The problem is that when you replace the text storage,
the typing attributes get reset. setFont: applies to
all of the text in the text view, but as you have
none, it (presumably) only changes the typing
attributes. So essentially, you are setting the typing
attributes, and then resetting them when you swap in a
different text storage.
To fix it, just set the typing attributes (using
setFont: or, even better, setTypingAttributes:)
*after* you call replaceTextStorage:, and everything
should work fine.
Cheers,
Keith
--- ORIGINAL MESSAGE ---
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 you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
_______________________________________________
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