Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force the cursor to the end of a NSTextField?

Tags:

cocoa

I am NSOpenPanel to select a file or folder from a user's machine. But when the user clicks "open" the cursor is at the beginning of the path that shows up in the text field. This is a problem because until you click in the textfield and arrow right, you won't see that the entire path is listed. For example if the path is:

/Users/jeremysmith/code/testfolder/testfolder2

It may only show:

/Users/jeremysmith/code/

since the cursor is at the beginning and the text field's width only goes to "code".

like image 258
Jeremy Smith Avatar asked Aug 18 '11 19:08

Jeremy Smith


3 Answers

I got this working on textfields by doing:

[[self.inputFileTextField currentEditor] moveToEndOfLine:nil];
like image 174
simon.d Avatar answered Nov 18 '22 10:11

simon.d


In Swift, since it's 2015:

self.textField.moveToEndOfDocument(nil)
like image 5
Dan Rosenstark Avatar answered Nov 18 '22 09:11

Dan Rosenstark


Here's my Swift solution:

self.fileTextField.currentEditor()?.moveToEndOfDocument(nil)
like image 5
BillyRayCyrus Avatar answered Nov 18 '22 11:11

BillyRayCyrus