gpt4 book ai didi

SwiftUI:如何在文本编辑器中禁用 "smart quotes"

转载 作者:行者123 更新时间:2023-12-04 16:38:04 27 4
gpt4 key购买 nike

我正在使用 SwiftUI 为 MacOS 开发基于 Python 的图形计算器。
https://github.com/snakajima/macplot
我使用 SwiftUI 的 TextEditor 作为 Python 代码的编辑器,但我无法弄清楚如何禁用智能引号(UITextInputTraits、smartQuotesType:UITextSmartQuotesType)。

        VStack {
TextEditor(text: $pythonScript.script)
HStack {
Button(action: {
pythonScript.run(clear: settings.shouldClear)
}, label: {
Text("Plot")
})
Toggle("Clear", isOn: $settings.shouldClear)
}
if let errorMsg = pythonScript.errorMsg {
Text(errorMsg)
.foregroundColor(.pink)
}
}

最佳答案

经过多次试验,我想出了以下解决方法。它依赖于 TextEditor 在 NSTextView 之上实现的事实,并在整个应用程序中更改其行为。它很丑,但有效。

// HACK to work-around the smart quote issue
extension NSTextView {
open override var frame: CGRect {
didSet {
self.isAutomaticQuoteSubstitutionEnabled = false
}
}
}

关于SwiftUI:如何在文本编辑器中禁用 "smart quotes",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66721935/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com