I would like to make a keybinding that simultaneously toggles the sidebar visibility and its focus. E.g., ctrl+u would:
– if the sidebar is not visible, open the sidebar and pass focus to the sidebar
– if the sidebar is visible, pass focus to the current view and close the sidebar
I could make the first part work like so:
class ShowAndFocusSidebarCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
view.window().set_sidebar_visible(True)
view.window().run_command("focus_side_bar")
For the second part, I am having trouble passing the focus to the current view from within the API. This line from the standard keybindings seems the most relevant:
{ "keys": ["ctrl+1"], "command": "focus_group", "args": { "group": 0 } },
This keybinding passes focus from the sidebar to the main view, but I don’t know how to run this command from within the TextCommand.run method. I’ve tried things like this:
class JustATestCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
## uncomment any of these lines (none work for me):
# view.focus_group(0)
# view.window().focus_group(0)
# view.window().active_window().focus_group(0)
How do I get the same effect as the above ctrl+1 keybinding command, from within the API?
Thanks!
UPDATE: Sorry, I’ve figured out that the key binding is not even being executed when the sidebar has focus. I’m getting a no command for selector: noop: message from the console.
If I understand right, the sidebar actually has its own set of independent keybindings when it has focus? Maybe even, all user-defined keybindings are completely ignored by the sidebar?