NSTextView - calculating current col (with tabs)
NSTextView - calculating current col (with tabs)
- Subject: NSTextView - calculating current col (with tabs)
- From: Duncan Campbell <email@hidden>
- Date: Thu, 16 Jun 2005 07:02:26 +1000
Hi folks,
I'm trying to write some code to calculate my current column in an NSTextView.
In my NSTextView subclass, I use something like the following:
NSRange selectionRange = [self selectedRange]; unsigned int selection = selectionRange.location; unsigned int end = [[self string] lineRangeForRange:selectionRange].location-1;
return (selection-end); which works great, however it is counting the <tab> char as a single char - where it should actually count it as (in my example) 4 chars.
I could simply add "numberofTabs*tabWidth" to the calculation, however this would also be incorrect since tabbing actually takes you to the next tab-stop, and does not simply add the tabwidth to the current y position.
Does anyone have any code that will correctly calculate the current col?
(for instance, if I type "abc" and then press <tab> twice I should be in col 8. Likewise, if I just press <tab> twice I would also end up in col 8).
thx for any advice.
D.
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