Is there a way for me to find out where my cursor is in the text. I don’t know what it’s called, the “line that shows you where your going to type.” (Now I feel stupid ) At least is there a way to get a number telling me that information. Example:
“Hi.| How are you?”
That pipe shows me were my cursor is. That cursor is 4 characters away from the beginning. This action [that would help me find out where my cursor is in the text] would return 4.
Hope my problem is not to confusing.
-dylanweber
I spilled apple juice on my mac. It doesn’t break it, it just makes it more “appley.”
selectedRange will return a list of two numbers: the first is the (zero-based) offset of the selection, and the second is the number of characters selected. But it only works on an NSTextView, not an NSTextField, AFAIK.
You can use selectedRanges by getting the current editor of the text field but it doesn’t make much sense here due to the fact that you cannot select multiple ranges in an NSTextField. You will still only get an array of one range.
Got it! I used “location of (textfield’s selectedRange())” to give me the cursor location as a number and changed the text field to text view. Is there a way to when you press enter like on a text field, text view does your actions? Please help!
The reason I want this service is because I am making a URL shortener. Instead of putting it on the end automatically, it will get the offset of the cursor and then put the shortened URL were the cursor is or replace the selected characters.
EDIT:
Oh, I have to press the button. I keep pressing enter, like normal people. Now it works.
I need help… How do I implement this into my app? I need help. I added the object to the Nib and I add those two files into my projects class. I changed the line that gets the information to work with my variables, but it says:
To get the selected range of the tweet box you need to put the code in a new handler and attach it to the TinyURL! button. Getting the range of a text field requires the text field have focus.