• 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
Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
      • From: Douglas Davidson <email@hidden>
    • Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
      • From: Jérôme Laurens <email@hidden>
References: 
 >attributesAtIndex:effectiveRange: vs the insertion point at end of text (From: Kirk Kerekes <email@hidden>)

  • Prev by Date: Re: Non user-selectable NSMixedState
  • Next by Date: Re: threads, notifications and DOs
  • Previous by thread: attributesAtIndex:effectiveRange: vs the insertion point at end of text
  • Next by thread: Re: attributesAtIndex:effectiveRange: vs the insertion point at end of text
  • Index(es):
    • Date
    • Thread