Switching textstorage of NSTextViews back and forth

Posted by Jakob Dam Jensen on Stack Overflow See other posts from Stack Overflow or by Jakob Dam Jensen
Published on 2010-06-16T17:10:27Z Indexed on 2010/06/16 18:22 UTC
Read the original article Hit count: 283

Filed under:
|

I'm trying to make a feature in a product which gives the user the ability to split a textview into two. The way this is done is by removing the textview from it's superview, making a NSSplitView and adding the textview as well as a new NSTextView instance to this splitview. Lastly I make these two textviews share the same textstorage in order to make them share the same content.

It works great. But the problem is when I want to make one of the two textviews change textstorage. The replaceTextStorage method in NSLayoutManager causes both NSTextView to change textStorage. The API documentation states:

replaceTextStorage: All NSLayoutManager objects sharing the original NSTextStorage object then share the new one. This method makes all the adjustments necessary to keep these relationships intact, unlike setTextStorage:.

So it makes sense that it would do this. But the question is how do I make it possible to have two (or more) textviews first share the same storage and after that having them using their own?

I've tried replacing the layoutManager and even making new instances of NSTextViews but no luck...

Any suggestions?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa