• 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
NSTextView getting the cursor col/row
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextView getting the cursor col/row


  • Subject: NSTextView getting the cursor col/row
  • From: Duncan Campbell <email@hidden>
  • Date: Fri, 6 May 2005 15:45:59 +1000

Hey folks.

I'm trying to figure out how to get the current col/row of the cursor in an NSTextView subclass. I've searched the mailing list without too much joy...

I'm using this to get the current col (which seems to work):

    NSRange selectionRange = [self selectedRange];
    unsigned int selection = selectionRange.location;
    unsigned int end = [[self string] lineRangeForRange:selectionRange].location-1;

    

    currentCol = (selection-end);

But am now trying to figure out how to get the current row.

So far i've come up with the following that seems to work, except it doesn't calculate correctly when the cursor is in the 1st column. Can anyone offer any advise (and perhaps a better version of this code? - i don't think using a for..next loop like this is particularly efficient):

    NSRange selectionRange = [self selectedRange];
    unsigned currentRow, idx, length =  selectionRange.location;

    for (idx = 0, currentRow = 0; idx < length; currentRow++)
        idx = NSMaxRange([[self string] lineRangeForRange:NSMakeRange(idx,0)]);

 


Many thanks.

Duncan Campbell
=====================
http://www.duncanandsarah.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

  • Follow-Ups:
    • Re: NSTextView getting the cursor col/row
      • From: Ondra Cada <email@hidden>
  • Prev by Date: Re: [NSConnection release] anxiety
  • Next by Date: Function to write to one pixel?
  • Previous by thread: Re: Weak link framework problem
  • Next by thread: Re: NSTextView getting the cursor col/row
  • Index(es):
    • Date
    • Thread