• 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: Line numbers in IDE
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Line numbers in IDE


  • Subject: Re: Line numbers in IDE
  • From: Glenn Andreas <email@hidden>
  • Date: Thu, 26 Feb 2004 09:09:20 -0600

At 11:23 AM -0800 2/25/04, Josh Black wrote:
Hi -

Thanks for the response, but I was hoping to learn how to implement
this myself. I had heard that one way to do it was to look at the
vertical rulers for the NSScrollView that encloses the NSTextView, and
possibly subclass NSRulerView as a way to draw the line numbers. I've
been working with this, but can't seem to get it to do what I want.

Josh

That's exactly what I do - for the most part, it works well, but there are a couple of tricky parts:

The vertical ruler actually entends below the content area of the document and includes the area next to the horizontal scrollbar. You need to draw that area because otherwise, when scrolling, you won't get a redraw messsage for that area (so if you don't draw it, you get weird stripes of things that don't get drawn).

Avoid using patterns unless you feel like messing with pattern alignment code (though at least you can solve this in 10.2 - in 10.1 it wasn't possible).

There is no built in way to get the line number from a NSTextView - the naive way of taking the vertical coordinate and dividing by the line height works so long as you don't wrap the text (assuming you mean "programmer lines" as oppose to "individual wrapped layed out lines").

If you want to support wrapped text, or different line heights, you're going to have to take the vertical component and convert it to a character index in the text and then convert that to a line number - the first part can be done with the help of the layout manager, the second part is easy to calculate, except that it ends up being O(n), so long files will signficantly slow down updating (at which point you'll need to implement some sort of cache to speed up character postion to line number calculations)

You might need to manually invalidate the ruler based on text changes (for example, wrapping text would move the line numbers so you'll need to do that yourself).

--
Glenn Andreas email@hidden mondo blobbo, Cythera, Theldrow, oh my!
Mad, Bad, and Dangerous to Know
_______________________________________________
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: 
 >Re: Line numbers in IDE (From: Josh Black <email@hidden>)

  • Prev by Date: Re: Problems with Distributed Objects
  • Next by Date: Very simple - UNIX like - filename expansion?
  • Previous by thread: Re: Line numbers in IDE
  • Next by thread: Re: Line numbers in IDE
  • Index(es):
    • Date
    • Thread