Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The site that is referenced in the comments to the accepted answer ... is now "SUSPENDED" by the webhost, and Google cache doesn't have the screenshot that contains the key step.</p> <p>So, here's an alternative solution I found that:</p> <ol> <li>works perfectly</li> <li>does NOT require subclassing</li> </ol> <p>For some keys (Enter, Delete, Backspace, etc), Apple does NOT invoke the normal controlTextDidEndEditing: etc methods. Instead, Apple does individual selectors for each magic key - but there's a method you can use to intercept it.</p> <p>Apple's official docs here:</p> <p><a href="https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextEditing/TextEditing.html#//apple_ref/doc/uid/TP40009459-CH3-SW31" rel="nofollow noreferrer">https://developer.apple.com/library/mac/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextEditing/TextEditing.html#//apple_ref/doc/uid/TP40009459-CH3-SW31</a></p> <p>...but in case that vanishes / gets moved, add this method into your delegate:</p> <pre><code>- (BOOL)control:(NSControl *)control textView:(NSTextView *)fieldEditor doCommandBySelector:(SEL)commandSelector { BOOL retval = NO; if (commandSelector == @selector(insertNewline:)) { retval = YES; // causes Apple to NOT fire the default enter action // Do your special handling of the "enter" key here } NSLog(@"Selector = %@", NSStringFromSelector( commandSelector ) ); return retval; } </code></pre> <p>In my case, I wanted to override the backspace key too - running the app with this method, I got output saying that the selector was "deleteBackward:", so I added another if-statement in there to react to that.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload