From b5d8b4f3de3a65b7debd3ddb6da2c28823044a00 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 26 Jul 2014 11:18:34 -0400 Subject: [PATCH] Adjusted autocompletion settings for TextField on Mac OS X. --- redo/controls_darwin.m | 2 +- redo/window_darwin.m | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/redo/controls_darwin.m b/redo/controls_darwin.m index 73192c1..23d15e2 100644 --- a/redo/controls_darwin.m +++ b/redo/controls_darwin.m @@ -106,7 +106,7 @@ static id finishNewTextField(NSTextField *t) // same for text fields and password fields setStandardControlFont((id) t); // TODO border (Interface Builder setting is confusing) - // TODO smart quotes + // smart quotes and other autocorrect features are handled by the window; see newWindow() in window_darwin.m for details // Interface Builder does this to make the text box behave properly // this disables both word wrap AND ellipsizing in one fell swoop // however, we need to send it to the control's cell, not to the control directly diff --git a/redo/window_darwin.m b/redo/window_darwin.m index a923ef5..9a02862 100644 --- a/redo/window_darwin.m +++ b/redo/window_darwin.m @@ -38,10 +38,26 @@ id newWindow(intptr_t width, intptr_t height) { - return [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) + NSWindow *w; + NSTextView *tv; + + w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height) styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask) backing:NSBackingStoreBuffered defer:YES]; + // we do not want substitutions + // text fields, labels, etc. take their smart quotes and other autocorrect settings from their parent window, which provides a shared "field editor" + // so we have to turn them off here + // thanks akempgen in irc.freenode.net/#macdev + // for some reason, this selector returns NSText but is documented to return NSTextView... + // TODO isolate into its own function when (if?) we add TextArea + tv = (NSTextView *) [w fieldEditor:YES forObject:nil]; + [tv setEnabledTextCheckingTypes:0]; + [tv setAutomaticDashSubstitutionEnabled:NO]; + // don't worry about automatic data detection; it won't change stringValue (thanks pretty_function in irc.freenode.net/#macdev) + [tv setAutomaticSpellingCorrectionEnabled:NO]; + [tv setAutomaticTextReplacementEnabled:NO]; + return w; } void windowSetDelegate(id win, void *w)