Swapping the NSTextContainer on an NSTextView
Swapping the NSTextContainer on an NSTextView
- Subject: Swapping the NSTextContainer on an NSTextView
- From: Robert Goldsmith <email@hidden>
- Date: Tue, 3 Feb 2004 19:15:03 +0000
Hi all :)
I remember there being a discussion about swapping out NSTextContainers
with an NSTextView to show multiple text contents - like projectBuilder
does - but can't find any agreed upon method in the archives. Before I
went hunting in the archives I trawled through Apple's info on the text
system and, following their info, am building my own text system
structure starting with an NSTextStorage, adding an NSLayoutManager and
an NSTextContainer. Then I have problems. When I either
setTextContainer or replaceTextContainer for the NSTextView or call
setTextView on the NSTextContainer to swap the view contents, all works
fine except for:
1) If I select text in the view, then swap the containers, the view
seems to try and select the same range in the second view. This is not
correct as the selection should move with the content, not be
remembered by the view. Worse, if the second content is shorter than
the first, the selection fails with an exception.
exception:
2004-02-03 19:10:44.111 Cruithne[1871] Access invalid attribute
location 67 (length 57)
2004-02-03 19:10:58.936 Cruithne[1871] *** Assertion failure in
-[NSMutableRLEArray objectAtIndex:effectiveRange:runIndex:],
String.subproj/NSAttributedString.m:1015
2) Similarly, if I have clicked on the first text to edit somewhere
further down than exists in the second text, then switch, an exception
is raised when the view tries to move the caret and you have to click a
second time to actually move the caret
exception:
2004-02-03 19:10:25.295 Cruithne[1871] *** Assertion failure in
-[NSMutableRLEArray objectAtIndex:effectiveRange:],
String.subproj/NSAttributedString.m:1009
2004-02-03 19:10:25.295 Cruithne[1871] Access invalid attribute
location 284 (length 57)
Oddly, I thought this was what the layoutManager and textContainers
kind of kept track of (selection and current edit position) but
obviously not. Do I really have to go to the effort of storing all this
extra info myself and resetting it when I switch? It seems silly to do
so when I really should only care about the textStorage, according to
Apple's docs.
Anyone remember the solution?
This is with the NSTextContainer setting the NSTextView to use using
the setTextView: method. I am assuming that as a view can only have one
associated container, the previous container is dropped for the new
one, which is fine as I keep hold of it through my textStorage
instance.
Any help appreciated!
---
GnuPG public key:
http://www.Far-Blue.co.uk/
[demime 0.98b removed an attachment of type application/pgp-signature which had a name of PGP.sig]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.