PowerShell / PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
MIT License
632 stars 215 forks source link

Add Keyboard Shortcut to Register-EditorCommand #630

Open jdhitsolutions opened 6 years ago

jdhitsolutions commented 6 years ago

This might just be me, but I would love to see an additional parameter for Register-EditorCommand to define a keyboard shortcut. Right now, I have to manually add a keyboard shortcut, which I suppose isn't that difficult now that I know how. But figuring that out took some time since I couldn't find any useful documentation. It would be much easier to make this part of the register command.

SeeminglyScience commented 6 years ago

Oh wow, I didn't realize we could set shortcuts for editor commands in VSCode yet! Thank you for prompting me to check :)

For now, so it's documented somewhere, here is an example:

    {
        "key": "alt+shift+s",
        "command": "PowerShell.InvokeRegisteredEditorCommand",
        "args": {
            "commandName": "ConvertToSplatExpression"
        },
        "when": "editorLangId == 'powershell'"
    }

You can get the name of the editor command you want to bind using this:

$psEditor.GetCommands()

The property you want to use for commandName is Name.

As for the parameter on Register-EditorCommand, that was the idea iirc, but at the time VSCode required keyboard shortcuts to be declared statically in the extension manifest file. I think that's still the case, but if it isn't then this would definitely be possible.

That said, in the mean time we should consider at least adding the parameter and updating the request so other editors like Atom can implement support for it.

TylerLeonhardt commented 6 years ago

Just did some research. I don't think this is possible still in VSCode.

Also, this will require some amount of work to implement there. Right now, all of the "registered editor commands" are treated as 1 command with different values for an argument. In other words, an editor command "foo" is actually triggering the "RegisteredEditorCommand" with the name argument "foo".

This will either need to be changed to "true dynamically added editor commands" or a way to somehow get a keybinding to fire a command with a particular value of an argument.

SeeminglyScience commented 6 years ago

or a way to somehow get a keybinding to fire a command with a particular value of an argument.

That you can already do (see example above). The trick is registering the shortcut dynamically, which I don't think is currently possible.

TylerLeonhardt commented 6 years ago

Ahh... I totally missed that. Oops 😊