• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
attributesAtIndex:effectiveRange: vs the insertion point at end of text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.
  • Follow-Ups:
    • Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
      • From: Dave Fayram <email@hidden>
  • Prev by Date: Re: Non user-selectable NSMixedState
  • Next by Date: Re: Non user-selectable NSMixedState
  • Previous by thread: ANN: Learning Cocoa with Objective-C, 2nd Edition
  • Next by thread: Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
  • Index(es):
    • Date
    • Thread