I have a NSTextView with the 'Smart Quotes' option disabled:
However, if I were to type:
'hello world'
Into the textview, it instanly gets replaced with:
‘hello world’
(see how the single quotes have been replaced).
I thought disabling smart quotes would have taken care of this, but it does not seem to of helped. Any suggestions on how I can get these prettier quotes to go away?
You can disable smart quotes for your NSTextView with:
self.textView.automaticQuoteSubstitutionEnabled = NO;
Not setting the checkmark in the interface builder doesn't seem to work since OS X 10.9 Mavericks.
See NSTextView setAutomaticQuoteSubstitutionEnabled:
Also you can use this for a more detailed control over the text replacement.
self.textView.enabledTextCheckingTypes = 0;
See NSTextView setEnabledTextCheckingTypes:
Also in Mavericks there is smart quotes enabled by default in System Preferences → Keyboard → Text. You can disable this as a personal preference.
This problem is still not fixed as of Yosemite / Xcode 6.1
To turn off all the substitution options that IB seems to ignore, I had to do this:
self.textView.automaticQuoteSubstitutionEnabled = NO;
self.textView.automaticDashSubstitutionEnabled = NO;
self.textView.automaticTextReplacementEnabled = NO;
Xcode 7.3 still have this problem.
The way to set these properties in IB.
Swift 4 extension to make any NSTextView monospace
Usage:
@IBOutlet var textViewJSONPushBody: NSTextView!
@IBOutlet var textViewConsole: NSTextView!
... viewDidLoad(){
//JSON editor - larger font
self.textViewJSONPushBody.makePlainText(withFontSize: 12.0)
//Log view - smaller
//defaults to sys font - small size
self.textViewConsole.makePlainText()
//or set fontSize
self.textViewConsole.makePlainText(withFontSize: 10.0)
}
NSTextView+PlainText.swift
//
// NSTextView+PlainText.swift
// GetStarted_NH_MacOS
//
// Created by Brian Clear on 12/07/2018.
// Copyright © 2018 City of London Consulting Limited. All rights reserved.
//
import Foundation
import AppKit
extension NSTextView{
/*
Usage:
@IBOutlet var textViewJSONPushBody: NSTextView!
viewDidLoad(){
//JSON editor
self.textViewJSONPushBody.makePlainText(withFontSize: 12.0)
//Log view - smaller
//defaults to sys font - small size
self.textViewConsole.makePlainText()
self.textViewConsole.makePlainText(withFontSize: 10.0)
}
*/
func makePlainText(withFontSize
fontSize: CGFloat = NSFont.smallSystemFontSize)
{
//---------------------------------------------------------
//FONT - monospaced
//---------------------------------------------------------
//small font
//self.font = NSFont.userFixedPitchFont(ofSize: NSFont.smallSystemFontSize)
//medium font
self.font = NSFont.userFixedPitchFont(ofSize: NSFont.systemFontSize)
//---------------------------------------------------------
self.isRulerVisible = false
self.isFieldEditor = false
self.isRichText = false
//---------------------------------------------------------
//smart quotes mess up json
//https://stackoverflow.com/questions/19801601/nstextview-with-smart-quotes-disabled-still-replaces-quotes
self.isAutomaticQuoteSubstitutionEnabled = false
//---------------------------------------------------------
self.isAutomaticLinkDetectionEnabled = false
self.isContinuousSpellCheckingEnabled = false
self.isGrammarCheckingEnabled = false
self.isAutomaticDashSubstitutionEnabled = false
self.isAutomaticDataDetectionEnabled = false
self.isAutomaticSpellingCorrectionEnabled = false
self.isAutomaticTextReplacementEnabled = false
self.isIncrementalSearchingEnabled = false
self.isAutomaticTextCompletionEnabled = false
//---------------------------------------------------------
//see also
//https://stackoverflow.com/questions/19801601/nstextview-with-smart-quotes-disabled-still-replaces-quotes
//self.enabledTextCheckingTypes =
//---------------------------------------------------------
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With