I have a key binding defined in a plugin’s Default (Linux).sublime-keymap
like this:
{
"keys": ["ctrl+7"],
"command": "my_plugin_command_name",
"context": [{"key": "my_plugin_key"}]
},
The plugin has an on_query_context()
method which returns a boolean value as to whether the key binding should be triggered, something like this (simplified):
class PluginEventListener(sublime_plugin.EventListener):
def on_query_context(self, view, key, operator, operand, match_all):
return key == "my_plugin_key" and is_active == True
The above all worked fine until I added the same keys to my Packages/User/Default (Linux).sublime-keymap
file.
{
"keys": ["ctrl+7"],
"command": "focus_group",
"args": {"group": 0}
},
Now ctrl+7
changes the group even when the on_query_context()
method returns true. Fair enough Packages/User/Default (Linux).sublime-keymap
is loaded after my plugin’s .sublime-keymap
file and so overrides the key binding.
So how do I set the context in my Packages/User/Default (Linux).sublime-keymap
file and in my on_query_context()
method so that it only triggers if NOT my_plugin_key
?
{
"keys": ["ctrl+7"],
"command": "focus_group",
"args": { "group": 0 },
"context": [{"key": "my_plugin_key" BUT SOMEHOW NOT my_plugin_key}]
},
I have already figured out that I can fix things by adding the bindings in the order of precedence which I require in my Packages/User/Default (Linux).sublime-keymap
file (as shown below), but it seems inelegant, especially when you bear in mind that I’ve got to add a whole bunch, and I’d like to expand my knowledge and do it right… assuming there is a way to do this?
{
"keys": ["ctrl+7"],
"command": "focus_group",
"args": { "group": 0 }
},
{
"keys": ["ctrl+7"],
"command": "my_plugin_command_name",
"context": [{"key": "my_plugin_key"}]
},
Thanks.