• 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
NSTextView textStorage woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextView textStorage woes


  • Subject: NSTextView textStorage woes
  • From: Duncan Campbell <email@hidden>
  • Date: Fri, 12 Aug 2005 16:37:55 +1000

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: This email sent to email@hidden
  • Prev by Date: grouping items in toolbar
  • Next by Date: Re: Trivial Bindings question
  • Previous by thread: Re: grouping items in toolbar
  • Next by thread: RE: NSTextView textStorage woes
  • Index(es):
    • Date
    • Thread