Sublime Forum

Help with contexts

#1

I’d like to understand how to properly handle contexts, because if there’s a right way to do it, I can’t see it.

I have these two keybindings:

{ "keys": ["h"],
    "args": {"paste_previous": true},
    "context": [{"key": "clip_man", "operator": "equal", "operand": "non_stop"}],
    "command": "clipboard_manager"
},

and:

{ "keys": ["h"],
    "command": "spp_file_panel_key",
    "args": {"key": "history_browse"},
    "context": [{"key": "panel_visible"}, {"key": "panel", "operator": "equal", "operand": "output.spp_file_operations"}]
},

The second one comes later in the plugin load order, but the context returns false if the panel isn’t open. But I would expect that the first keybinding, if the context is respected, would work. Instead it does not.

It is as if only the last context key is evaluated, and if it returns false, the other context (which would return true) doesn’t work anyway.

But a strange thing, is that if I invert the two keybindings, both of them work.

How can I handle this situation?


This is the query I use for the first keybinding, the second one doesn’t have a query context(it had, but I removed it in the hope of simplifying the problem, still no solution).

def on_query_context(self, view, key, operator, operand, match_all):

    if ClipboardManagerListener.command_mode:
        if key == "clip_man":
            if operator == sublime.OP_EQUAL and operand == "non_stop":
                pass
            else:
                ClipboardManagerListener.command_mode = False
                view.erase_status("clip_man")
            view.window().destroy_output_panel('choose_and_paste')
            return True
        else:
            ClipboardManagerListener.command_mode = False
            view.erase_status("clip_man")
    return None
0 Likes