I have a view with a grid of cells.
When user click on a cell, an NSTextFied overlays the cell to allow for entering value.
When Tab, Shift-tab or return are pressed, the editing cell moves to next or previous one.
This is done in the
override func controlTextDidEndEditing(notification: NSNotification)I would like to do the same with arrow keys, to allow for fast moving in the grid.
When arrow is pressed, cursor moves in the TextField ; I would need to intercept this pressed key and act accordingly. How can I do this ?
I tried to implement
override func keyDown(theEvent: NSEvent!)but the method is not called when arrowkey is pressed (it is called when any other key is typed).
I tried also :
override func controlTextDidBeginEditing(obj: NSNotification) {
}Doesn't work either.
You're tap dancing in a minefield here.
a. How could you possibly want to have text editing without the arrow keys to move the cursor within the text? There is nothing more frustrating to users than standard UI elements with non-standard behavior.
b. Of course 'keyDown' is called — somewhere. The particular method implementation is chosen by traversing the responder chain. So, it matters where you put your override (you didn't say where you put yours).
c. When a text field is being edited, the editing does not happen in the text field, but in an auxiliary field editor belonging to the window as a whole. That's where you would have to override 'keyDown' in this case, which means subclassing the field editor, and that's a world of pain you probably don't want.
d. The easiest way to modify the tab/return behavior is not in the delegate method 'controlTextDidEndEditing', but in delegate method 'control:textView:doCommandBySelector:'. As it happens, you can detect arrow key usage in this method too.