Re: No NSTextContainer being returned for glyph range
Re: No NSTextContainer being returned for glyph range
- Subject: Re: No NSTextContainer being returned for glyph range
- From: "Mike R. Manzano" <email@hidden>
- Date: Wed, 6 Sep 2006 16:49:34 -0700
The configuration is one layout manager to many containers, each with
a view.
I do have
layoutManager:didCompleteLayoutForTextContainer:atEnd:
defined to add containers like the TextEdit example.
Because of this I assume layout will finish and end in a state where
there's a container for all glyphs before the NSAssert1 line.
More specifically, I am trying to scroll my parent clip view to the
location of the insertion point. I am doing this in two places inside
of which I am calling my own method, scrollToVisible (see far below):
(1) In response to a notification that I post in an NSWindow
subclass' zoom:, which is handled by this method:
- (void) frameDidChange: (NSNotification*) notification
{
// Ensure the object belongs to this particular document
(notification object
// could actually be from another document).
if( [ notification object ] == [ self window] )
{
[ self performSelector:@selector( redimensionView )
withObject:nil afterDelay:0.0f ] ;
[ self performSelector:@selector( redimensionColumns ) // Resizes a
bunch of sub views
withObject:nil afterDelay:0.0f ] ; // containing the text corpus
in question.
// This is where I believe a re-layout is
// kicked off
// ********* HERE IT IS *********
[ self performSelector:@selector( scrollToVisible )
withObject:nil afterDelay:0.0f ] ;
}
} // frameDidChange:
(2) While handling text input:
- (void)textViewDidChangeSelection:(NSNotification *)aNotification
{
// Ensure that this notification is from our document
if( [ (NSTextView*) [ aNotification object ] window ] == [ self
window ] )
{
[…]
// Ensure that the current typing area is fully in view
[ self performSelector:@selector( scrollToVisible )
withObject:nil afterDelay:0.0f ] ;
[…]
Thanks again for the quick response!
~ Mike
alephx01 (at) mac (dot) com
// Scroll the nearest adjacent clip view so that the view with the
cursor is visible
- (void) scrollToVisible
{
NSLayoutManager* lm = [ [ _textStorage layoutManagers ]
objectAtIndex:0 ] ;
// Find the glyph range for this range
NSRange glyphRange = [ lm
glyphRangeForCharacterRange:_currentCursorPosition
actualCharacterRange:nil ] ;
// Get the container for this glyph range
if( [ lm isValidGlyphIndex:glyphRange.location ] )
{
NSTextContainer* container = [ lm
textContainerForGlyphAtIndex:glyphRange.location effectiveRange:nil
withoutAdditionalLayout:NO ] ;
NSAssert1( container != nil , @"container is nil for char range %@" ,
NSStringForRange( [ lm characterRangeForGlyphRange:glyphRange
actualGlyphRange:nil ] ) ) ;
// Get the text view
NSTextView* tv = [ container textView ] ;
NSAssert( tv != nil , @"tv is nil!" ) ;
// Get the frame of the text view
NSRect tvFrame = [ tv frame ] ;
// Ask our parent to scroll here
[ self scrollRectToVisible:tvFrame ] ;
[…]
On Sep 6, 2006, at 4:11 PM, Douglas Davidson wrote:
On Sep 6, 2006, at 3:44 PM, Mike R. Manzano wrote:
The assertion (NSAssert1) is being thrown every now and then
during program execution. The if statement validates that the
glyphRange in question is valid. The call to
textContainerForGlyphAtIndex:effectiveRange:withoutAdditionalLayout:
should finish the layout so that a valid response can be returned.
My question is, if the glyph range is a valid one, and the layout
is ensured to be finished, then can't I assume a valid container
to be returned every time?
You don't say much about how your text containers are configured.
Layout can be complete and a glyph can still have no text container
if the text containers fill up and the glyph happens to lie beyond
the text that fits.
Douglas Davidson
_______________________________________________
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