如何在 WKWebView 中关闭 OS X 的智能引号替换? [英] How can I turn off OS X's Smart Quotes replacement in my WKWebView?

查看:20
本文介绍了如何在 WKWebView 中关闭 OS X 的智能引号替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含 WKWebView 的 Mac 应用程序.Web 视图中的 HTML 包含一个 input 字段,用户可以在其中键入代码(实际上是 Ruby).当我在此字段中输入引号 (") 时,它会自动变成花哨的卷曲引号 (").由于 Ruby 字符串使用 ASCII 引号作为分隔符,这是错误的.

I'm developing a Mac application that contains a WKWebView. The HTML in the web view contains an input field into which the user types code (Ruby, in fact). When I type a quote (") into this field, it is automatically turned into a fancy curly quote ("). Since Ruby strings use ASCII quotes as delimiters this is wrong.

目前,我正在使用用户输入的内容,并在使用代码之前将大括号替换为 ASCII 引号,但显然这并不理想.

At the moment I'm taking what the user enters and substituting from curly quotes to ASCII quotes before using the code, but obviously this is not ideal.

我不知道如何禁用此 OS X 功能.显然,用户可以在全局级别的系统偏好设置中执行此操作,但我只想在我的应用中将其关闭.

I can't figure out how I can disable this OS X feature. Obviously it's possible for the user to do in System Preferences at a global level, but I just want to turn it off in my app.

WKWebView 或应用程序包本身或某处是否有一些配置可以关闭此功能?有 HTML 或 CSS 选项吗?我应该使用不同类型的 HTML 输入字段吗?基本上我可以在整个堆栈中的哪个位置进行干预以关闭此功能?

Is there some configuration on the WKWebView, or on the app bundle itself, or somewhere, that can turn this off? Is there an HTML or CSS option? Should I be using a different type of HTML input field? Basically where in the whole stack can I intervene to turn this feature off?

推荐答案

当您在系统偏好设置(键盘 > 文本 > 使用智能引号和破折号)中切换设置时,它会为 NSAutomaticQuoteSubstitutionEnabled 键设置一个值code> 在用户的全局首选项域中.我通过比较 defaults read -g 从之前到之后的输出来确定这一点.

When you toggle the setting in System Preferences (Keyboard > Text > Use smart quotes and dashes), it sets a value for the key NSAutomaticQuoteSubstitutionEnabled in the user's global preferences domain. I determined this by comparing the output of defaults read -g from before to after.

您可以尝试在应用启动初期将应用域设置为 false,以查看是否会为您的应用禁用它:

You can try setting that to false for your app domain early in your app's start-up to see if that disables it for your app:

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"NSAutomaticQuoteSubstitutionEnabled"];

-applicationWillFinishLaunching: 甚至 main() 中试试.

Try that in -applicationWillFinishLaunching: or even main().

当然,如果可行,它将在您的整个应用程序中禁用它,而不仅仅是您的 WKWebView.

Of course, if that works it will disable it throughout your app, rather than just your WKWebView.

这篇关于如何在 WKWebView 中关闭 OS X 的智能引号替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆