Package keybinding: win and mac [SOLVED]


#1

Hello.
I am developing an extension, and would love to use consistent keybinding between Win and Mac. I have keybinding defined in json file, which works great on mac, but, of course, fails on windows.

{
    "atom-workspace": {
        "cmd-alt-r": "do-that-magic-baby"
    }
}

What I am trying to achieve here, is to be able to run command with cmd-alt-r on Mac and ctrl-alt-r on Windows. How do I achieve this? I tried looking in the docs with no success.

Do I add both keybinding in json file? Like this? But then there would be 2 same commands on Mac. I am confused :confused:

{
    "atom-workspace": {
        "cmd-alt-r": "do-that-magic-baby",
        "ctrl-alt-r": "do-that-magic-baby"
    }
}

Thank you.


#2

You can have platform specific keybindings by doing something like the following

'.platform-linux atom-workspace, .platform-win32 atom-workspace':
  'ctrl-alt-r': 'do-that-magic-baby'

'.platform-darwin atom-workspace':
  'cmd-alt-r': 'do-that-magic-baby'

Note that this is CSON syntax.
Hope that answers your question!


#3

Thanks @chrispahm, but is it possible to achieve this with JSON rather then CSON?


#4

This should be the equivalent JSON:

{
    ".platform-linux atom-workspace, .platform-win32 atom-workspace": {
        "ctrl-alt-r": "do-that-magic-baby"
    },
    ".platform-darwin atom-workspace": {
        "cmd-alt-r": "do-that-magic-baby"
    }
}

#5

@Thanks @chrispahm again. I also tried same thing after previous reply and ended up with similar snippet. Thanks.


#6

No worries, glad to help!