NSTextView getting the cursor col/row
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 =====================
|
_______________________________________________
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