attributesAtIndex:effectiveRange: vs the insertion point at end of text
attributesAtIndex:effectiveRange: vs the insertion point at end of text
- Subject: attributesAtIndex:effectiveRange: vs the insertion point at end of text
- From: Kirk Kerekes <email@hidden>
- Date: Tue, 17 Sep 2002 23:36:46 -0500
I am trying to provide some simple Carbon-style text attribute control
in my Cocoa app. As part of this, I need to determine the current text
attributes of the selection in a NSTextView.
Stripped to its essentials, I am doing:
NSTextStorage * ts = [tNoteView textStorage];
NSRange selection = [tNoteView selectedRange];
NSDictionary * attrs = [ts attributesAtIndex: selection.location
effectiveRange:nil];
Which appears to work just dandy except if I click at the end of the
text in the NSTextView. Then I get exceptions like:
-[NSMutableRLEArray objectAtIndex:effectiveRange:]
"'NSInternalInconsistencyException'
(reason 'Access invalid attribute location 6 (length 6)')"
It seems that attributesAtIndex:effectiveRange: is unhappy with the
seemingly valid notion of an attributed insertion point at the end of
text -- and yet the standard Font and Text menu items don't have this
problem. The error message is bizarre also -- how can an insertion
point imply a range with a "(length 6)"
The insertion point has to have attributes, so that they can be applied
to the next typed character. It seems doltish to have to special-case
this extremely _common_ case.
What am I missing?
I have tried this with -[NSAttributedStringAdditions
fontAttributesInRange:] also, with the identical exceptions.
_______________________________________________
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.