Sublime Forum

Custom command with selector in action menu is not working

#1

Hey there!
I’ve made a custom command with a $text input, is very basic. In my Default.sublime-commands file I’ve added:

[{
        "caption": "Git Changelog",
        "command": "git",
        "args": {"argv": ["changelog", "-t", "$text"]}
}]

And it’s working fine if used from the command palette.

If I add the same to Action.sublime-menu file, the command appears correctly in the menu but when clicked no input is opened, and the command is executed without the argument causing an error.

Am I missing something or this is not implemented yet?

Thanks a lot for this amazing software, huge Sublime suite fan :smile:

0 Likes

#2

For commands that gather input in the command palette, they need to be run from the command palette since they need to use it to gather the input.

One way to do that is to add it to the command palette directly as you’re doing. If you want to do it from a menu, you need to use a slightly different command to kick it off:

{
    "caption": "Git Changelog",
    "command": "show_command_palette",
    "args": 
    {
        "command": "git", 
        "args": {"argv": ["changelog", "-t", "$text"]}
    }
}

The show_command_palette command opens the command palette and then runs the command in it (as it would run if you added it directly), allowing you to trigger it from the menu and still gather input.

2 Likes

#3

I see, yes it works indeed! Have I missed this in the docs?

Thanks a lot for your time!

0 Likes

#4

The thing is, in your first example, you were running the command directly from the command palette (which is fine since the command palette is already open for the InputHandler to collect inputs). In your second case, your executing the command in the context of a menu. Since the command palette isn’t open, as @OdatNurd mentioned, you’d need to first open it and then run your custom command.

It isn’t any different in ST either were an entry in a .sublime-commands file is a pre requisite for an InputHandler to work and since ST & SM share a lot of common functionality together.

I believe it just recently got added to the docs about the necessary conditions for an InputHandler to work.
https://www.sublimetext.com/docs/api_reference.html#sublime_plugin.TextInputHandler

0 Likes