Re: NSTextView Line Number
Re: NSTextView Line Number
- Subject: Re: NSTextView Line Number
- From: SJB <email@hidden>
- Date: Fri, 14 Jan 2005 07:53:36 +1300 (NZDT)
Hi,
Thanks for the answer. I suspected that caching the
information myself would be the answer, but it just
seemed very odd that the line number wasn't tracked
somewhere in Cocoa.
Simon.
--- glenn andreas <email@hidden> wrote:
>
> 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
>
>
Find local movie times and trailers on Yahoo! Movies.
http://au.movies.yahoo.com
_______________________________________________
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