Somewhere along the way, I believe with Xojo 2014r3, the TextArea object gained the ability to get the automatic “smart quotes” feature from OS X.
As it turns out, my app needs to allow the user to type into a TextArea and the resulting text must not have the regular quotes auto-magically replaced with smart quotes.
I have tried turning off the “automatically check spelling” and “styled” properties of the TextArea, but neither of these disable the automatic substitution of smart quotes. For whatever reason, the TextField object doesn’t get smart quotes. Only TextArea objects.
Does anyone have any ideas how to keep OS X from replacing regular quotes with smart quotes in certain TextAreas?
in the KEYPRESS check if “KEY” is a smart quote character and return TRUE if it is
if they are inserted “automagically” then you will have to use REPLACEALL
Sub setAutomaticQuoteSubstitutionEnabled(t as TextArea, value as Boolean)
#if TargetCocoa then
Declare Function NSClassFromString Lib "Cocoa" (aClassName As CFStringRef) As Ptr
dim myTextArea as ptr
declare function documentView lib "Cocoa" selector "documentView" _
(obj_id as Integer) as Ptr
myTextArea = documentView(t.Handle)
Declare Sub setAutomaticQuoteSubstitutionEnabled Lib "Cocoa" Selector "setAutomaticQuoteSubstitutionEnabled:" _
(Id as ptr, value as Boolean)
setAutomaticQuoteSubstitutionEnabled (myTextArea, value)
#endif
End Sub
or a Button or CheckBox to toggle AutomaticQuoteSubstitution
#if TargetCocoa then
Declare Function NSClassFromString Lib "Cocoa" (aClassName As CFStringRef) As Ptr
dim myTextArea as ptr
declare function documentView lib "Cocoa" selector "documentView" _
(obj_id as Integer) as Ptr
myTextArea = documentView(TextArea1.Handle)
Declare Sub toggleAutomaticQuoteSubstitution Lib "Cocoa" Selector "toggleAutomaticQuoteSubstitution:"_
(Id as ptr)
toggleAutomaticQuoteSubstitution (myTextArea)
#endif
Thanks Axel Schneider, that’s the ticket. I did’t think of disabling it in the native NSTextView. At first I was doing a bunch of ReplaceAll() calls, but clearly, that’s a lot of processing to undo what the OS is doing, and the correct answer is to simply turn off the automatic stuff in the first place.
After playing with it for a while, I discovered that I also needed to turn off not only smart quotes, but also smart dashes and other automatic substitutions (like the user’s own defined substitutions). So, I ended up setting a few more of NSTextView’s flags:
#if TargetCocoa then
declare function NSClassFromString lib "Cocoa" (aClassName as CFStringRef) as Ptr
declare function documentView lib "Cocoa" selector "documentView" _
(obj_id as Integer) as Ptr
declare sub setAutomaticQuoteSubstitutionEnabled lib "Cocoa" _
selector "setAutomaticQuoteSubstitutionEnabled:" _
(id as ptr, value as Boolean)
declare sub setAutomaticDashSubstitutionEnabled lib "Cocoa" _
selector "setAutomaticDashSubstitutionEnabled:" _
(id as ptr, value as Boolean)
declare sub setAutomaticTextReplacementEnabled lib "Cocoa" _
selector "setAutomaticTextReplacementEnabled:" _
(id as ptr, value as Boolean)
dim myTextArea as ptr = documentView(self.Handle)
setAutomaticQuoteSubstitutionEnabled(myTextArea, value)
setAutomaticDashSubstitutionEnabled(myTextArea, value)
setAutomaticTextReplacementEnabled(myTextArea, value)
#endif
I just ran across this very problem…
and the above declares work well for OSX…
my question… is this an issue for Windows as well, and if so, anyone have a solution similar to the declares…
If necessary, I’ll resort to the REPLACE method but I’d rather not for sake of clarity and speed
I don’t believe it’s an issue on Windows. The smart quotes thing is a Mac text replacement feature. Users can opt to turn it off in System Preferences as well on a system-wide level.
…And REST API POST requests!! Grrr. Took me some hours to figure out why my API calls (request content entered into a textarea) were failing. It was friggin smart quotes!! Geez… I fixed it by doing the replaceall thing. Now I’m using the declares.
For those that still need this, Joe Ranieri posted a solution in Feedback back in 2013 that uses a different set of declares (from AppKit instead of Cocoa): <https://xojo.com/issue/25702>. Don’t exactly know what the difference is, but it worked for me.