Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double quote gets transformed. #45

Closed
jacola opened this issue Feb 16, 2022 · 6 comments
Closed

Double quote gets transformed. #45

jacola opened this issue Feb 16, 2022 · 6 comments

Comments

@jacola
Copy link

jacola commented Feb 16, 2022

Copy and paste works fine, but when typing double quotes into the JSON formatter, macOS transforms them to /slanted/ quotes.

{ "test": "darn" } becomes { “test”: “darn” } resulting in invalid JSON.

image

@DanielSouzaBertoldi
Copy link
Contributor

DanielSouzaBertoldi commented Feb 16, 2022

I dug a deep into this problem and to me (unexperienced Swift developer) it seems that the problem is the Smart Quotes feature that Mac has enabled by default. Disabling it in the System Preferences fixes this issue.

I tried to code something to fix this without needing to disable the Smart Quotes feature, but ran into a few problems:

There's a flag that can be used to disable this behavior programmatically, called isAutomaticQuoteSubstitutionEnabled but it's only available for the NSTextView view. Since the textView attribute of the TextViewSectionBase is actually of type NSView we can't directly access it (At least I think we can't, I tried a few things and got nowhere), nor convert it to a NSTextView.

One thing that worked was to use the replaceOccurrences function, but I didn't create a PR since to me seems kinda ugly to use it for this problem, and I don't know if there's another way to do it. The code ended up like:

    var string = "" {
        didSet {
            // using two replacingOccurrences since both quotes are actually different from one another
            self.textView.string = string.replacingOccurrences(of: "", with: "\"").replacingOccurrences(of: "", with: "\"")
            self.copyButton.stringContent = string
        }
    }

Note: I forgot to mention, but this 'solution' will not work for French quote symbols ( « » ) nor German ones ( „ “ ) :/

If anyone got any ideias on how to solve this problem more elegantly, let me know, I'll gladly create the PR fixing this 😄

@ObuchiYuki
Copy link
Collaborator

@jacola @DanielSouzaBertoldi Thank you for your issue!

I certainly think it's a serious problem too. I want to fix it. But I can't reproduce the problem. Could you please let me know your keyboard settings and how it is occured?

@DanielSouzaBertoldi
Copy link
Contributor

DanielSouzaBertoldi commented Feb 16, 2022

@ObuchiYuki my keyboard layout is Brazilian - ABNT2

my keyboard layout

If we copy and paste a json then it's formatted properly, but if we type a json then the Mac replaces the quotes for the slanted version of it, as can be seen in my GIF below.

Kapture 2022-02-16 at 12 59 15

@jacola
Copy link
Author

jacola commented Feb 17, 2022

I have standard keyboard settings as well for an English OS in Japanese region.
Screen Shot 2022-02-17 at 11 24 47

As @DanielSouzaBertoldi mentioned, this setting should stop the issue from having, but it's true by default.
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false

@ObuchiYuki
Copy link
Collaborator

@jacola @DanielSouzaBertoldi

I was able to reproduce and fix the bug. Thanks for your help!

タイトルなし

@ObuchiYuki
Copy link
Collaborator

@DanielSouzaBertoldi @jacola Thank you for your support! I can fix this bug!

You can get fixed version on
https://github.com/ObuchiYuki/DevToysMac/releases/tag/0.0.8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants