views:

23

answers:

1

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?

+1  A: 

If you want the two NSTextView to have difference NSTextStorage, then you have to create two parallel text systems.

First, start with the following architecture (this the one describe in the Text System Overview):

  • A common NSTextStorage
  • A first branch with NSLayoutManager/NSTextContainer/NSTextView
  • A second branch with NSLayoutManager/NSTextContainer/NSTextView

Then, call the replaceTextStorage: method on each NSLayoutManager to set different NSTextStorage.

Laurent Etiemble
Thank you so much... didn't see that at all... awesome
Jakob Dam Jensen