• 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: Calculating paragraph numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calculating paragraph numbers


  • Subject: Re: Calculating paragraph numbers
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 29 Jan 2004 09:55:45 -0800

On Jan 28, 2004, at 11:00 PM, Mark Alldritt wrote:

I'm trying to figure out how I can calculate the paragraph number of the
current selection in a text view. I've studied the code on
http://developer.apple.com/documentation/Cocoa/Conceptual/TextLayout/ Tasks/C
ountLines.html, but it suggests that I iterate over the entire text to count
the lines. Is there some way to get this information directly? Otherwise,
I can see this getting slower and slower as the length of text grows.

NSTextStorage, and its superclass NSMutableAttributedString, do not maintain paragraph number information for the text they contain, because the text system does not need this information. It often uses the range of the paragraph surrounding a particular location, but has no interest in numbering the paragraphs. Obviously you can determine this information by iterating through the text, but as you say this will be O(text length). The natural solution would be for you to cache this information. You can determine when the text changes in several ways; at the text view level, the text view's delegate is notified of all user changes to the text. At the text storage level, it is possible to keep track of all changes to the text.

Douglas Davidson
_______________________________________________
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.

References: 
 >Calculating paragraph numbers (From: Mark Alldritt <email@hidden>)

  • Prev by Date: Re: Notification redundancy
  • Next by Date: Re: Notification redundancy
  • Previous by thread: Calculating paragraph numbers
  • Next by thread: Re: Calculating paragraph numbers
  • Index(es):
    • Date
    • Thread