• 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: NSTextView Line Number
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView Line Number


  • Subject: Re: NSTextView Line Number
  • From: glenn andreas <email@hidden>
  • Date: Thu, 13 Jan 2005 09:09:59 -0600


On Jan 12, 2005, at 6:01 PM, SJB wrote:

Hi,
Does anyone have an easy way of getting the current
line number in an NSTextView?

I realise that I could just run through the text and
count the line ends, but that would get slower as the
file gets bigger.

Any suggestions or example code would be much
appreciated.


NSTextView doesn't keep track of any such line number information - you have two choices. Either count yourself (which slows things down on large files) or keep track of everything yourself in a parallel data structure which you update on all the delegate "textDidChange" calls.


In IDEKit I use to use the former but performance became unacceptable, and now do the latter, and works quite well. If you have a very simple case (no word wrap, fixed line height) you could also just take the y coordinate divided by the line height, but that doesn't work well for the more general case.

Glenn Andreas                      email@hidden 
 <http://www.gandreas.com/> oh my!
Mad, Bad, and Dangerous to Know

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTextView Line Number
      • From: SJB <email@hidden>
References: 
 >NSTextView Line Number (From: SJB <email@hidden>)

  • Prev by Date: Re: Cocoa/Objective-C's Relative Performance
  • Next by Date: Re: NSUnarchiver and StickiesDatabase
  • Previous by thread: NSTextView Line Number
  • Next by thread: Re: NSTextView Line Number
  • Index(es):
    • Date
    • Thread