Re: NSTextView Line Number
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