Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
- Subject: Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
- From: Dave Fayram <email@hidden>
- Date: Wed, 18 Sep 2002 01:20:03 -0700
I ran into the same problem, several methods in NSTextView seem to
break in this case.
What I did was detect if my selection began at the end of the text, and
if so decremented the insertion
point by 1. Usually this gets the behavior I'd more-or-less expect from
it.
I dunno why it breaks on that perfectly reasonable case, either. It's
really quite strange.
On Tuesday, September 17, 2002, at 09:36 PM, Kirk Kerekes wrote:
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.
- Dave Fayram
Freelance Coder / UCSB Student / Idealist
"Not everyone finds Drag'N'Drop as intuitive as they should."
_______________________________________________
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.