Can someone finalize the documentation on this page? https://www.sublimetext.com/docs/3/key_bindings.html#context
Right now, I am trying to assert that user is on the code editor panel, but I don’t know how it could be possibly called.
Can someone finalize the documentation on this page? https://www.sublimetext.com/docs/3/key_bindings.html#context
Right now, I am trying to assert that user is on the code editor panel, but I don’t know how it could be possibly called.
What do you mean with “code editor panel”? The normal view in the editor layout? That is not a panel at all. You could identify those views by checking setting.is_widget
for falsity.
I am fairly certain we are talking about the same thing.
For the sake of completeness:
As @FichteFoll mentioned, if you want to test for that, use the setting
context and check the is_widget
setting; that is set to true
when a view
is being used as an input widget, such as the text area in the command palette, in the console, etc.:
{ "keys": ["f1"], "command": "insert", "args": {"characters": "a"},
"context": [
{ "key": "setting.is_widget", "operator": "equal", "operand": false },
]
},
F1 will insert an a
in a file, but not in the input widget in the console, etc.
Out of curiosity, what sort of binding are you making that requires that you distinguish between editing a file and being in an input widget?
I am trying to fix that https://github.com/andriyko/sublime-robot-framework-assistant/blob/master/Default%20(Linux).sublime-keymap in the easiest way possible (note that the first two shortcuts clash with the sublime-native Find/Replace all)
The default bindings for those keys use the panel_has_focus
context to know that a panel is focused, so simplistically you could replace the bindings in your link with:
{ "keys": ["ctrl+alt+enter"], "command": "show_keyword_documentation",
"context": [
{"key": "panel_has_focus", "operator": "equal", "operand": false}
]
},
{ "keys": ["alt+enter"], "command": "jump_to_keyword",
"context": [
{"key": "panel_has_focus", "operator": "equal", "operand": false}
]
},
With that in place, the custom bindings will only apply when a panel is not open, but otherwise the default keys would apply instead.
That is why I think the documentation would warrant improvements. Unless I am looking at the wrong one.
"context": [{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
So, I guess that should be read as: when panel:find and panel has focus.
However, the leap from this to that:
{"key": "panel_has_focus", "operator": "equal", "operand": false}
Is not straightforward. Unless, it is “widely known” that everything is panels, except the main view.
I also tried to add this:
{ "key": "selector", "operator": "equal", "operand": "source.robot"},
(which I stole from Anaconda plugin), but it doesn’t seem to work (even though, the file is auto-highlighted as Robot Framework Syntax)
Thank you for your quick and complete response