Switching textstorage of NSTextViews back and forth
- by Jakob Dam Jensen
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?