• 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: Displaying line numbers at the left of a subclass of NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Displaying line numbers at the left of a subclass of NSTextView


  • Subject: Re: Displaying line numbers at the left of a subclass of NSTextView
  • From: Uli Kusterer <email@hidden>
  • Date: Mon, 20 Aug 2007 15:59:19 +0200

On 20.08.2007, at 06:47, Ricardo Diaz wrote:
Hi, how can I implement a rectangle on the left of the text view that displays the line numbers?

This question has been answered a couple times on this list. I actually just implemented something like this yesterday. There are more effective ways, but what I did was to put a view to the right of the NSTextView. I look at the textContainerOffset, visibleRect of the NSTextView and subscribe to bounds changed notifications on the NSClipView owned by the enclosingScrollView of my text view. That lets me update my view when the text view is scrolled.


To find out where to display my line numbers, I ask the textContainer, which gives you info about which character index is at which NSPoint and vice versa. Then I can compare that info to a list of line starts/ends I've generated. The line starts/ends list has to scan the whole text, which is kind of inefficient. You could probably do better by subclassing the layout manager and somehow making it do that once, but I haven't looked into stuff like that yet.

Most of this info was fairly easy to google up, and I encourage you to do that, because the blog postings contain numerous details you'd want to know.

Cheers,
-- M. Uli Kusterer
http://www.zathras.de



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Displaying line numbers at the left of a subclass of NSTextView (From: Ricardo Diaz <email@hidden>)

  • Prev by Date: Re: textStorage readFromURL does not like blanks
  • Next by Date: Re: Is this a bug of InterfaceBuilder?
  • Previous by thread: Re: Displaying line numbers at the left of a subclass of NSTextView
  • Next by thread: NSArrayController and Class objects
  • Index(es):
    • Date
    • Thread